n = int(input()) A = list(map(int, input().split())) mod = 10**9 + 7 if min(A) == 0: print(-1) elif max(A) >= 4: print(mod) else: ans = 1 Fact = [1, 1, 2, 6] for i in range(n): ans *= pow(A[i], Fact[A[i]]) print(mod % ans)