N = int(input()) A = list(map(int, input().split())) if 0 in A: print(-1) exit() M = 10**9 + 7 f = lambda x: 1 if x == 1 else x * f(x - 1) ans = 1 for a in A: if a > 3: print(M) exit() ans *= a**f(a) if ans > M: print(M) exit() print(M % ans)