import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) a.sort() mod = 10 ** 9 + 7 q = 1 for x in a: if x == 1: continue if x == 0: q = 0 break t = x for i in range(1, x + 1): t = pow(t, i) if q * t > mod: print(mod) exit(0) q *= t if q > 0: print(mod % q) else: print(-1)