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