import sys, math from itertools import permutations input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) if(n >= 4): print(0) exit(0) def f(x, y): if(math.gcd(x, y) >= 2): return 0 return (x - 1) * (y - 1) ans = math.inf for p in permutations(a): t = f(p[0], p[1]) if(n == 3): t = f(t, p[2]) ans = min(ans, t) print(ans, t, p) if(ans > 10 ** 18): ans = -1 print(ans)