import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) a = list(map(int, input().split())) if 0 in a: ans = -1 else: v = 1 for k in a: if k==1: pass elif k>=4: ans = M break else: d = [1,1,2,6] v *= pow(k, d[k]) if v>M: ans = M break else: ans = M%v print(ans)