import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 import itertools from math import gcd def f(x, y): if gcd(x, y) == 1: return x * y - x - y + 1 else: return 0 n = ii() a = li() if n >= 4: print(0) exit() ans = inf if n == 3: for v in itertools.permutations(a): ans = min(ans, f(f(v[0], v[1]), v[2])) else: ans = f(a[0], a[1]) print(ans)