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 for i in range(n): cnt = 1 for j in range(1, A[i] + 1): cnt *= j ans *= pow(A[i], cnt) print(mod % ans)