n = int(input()) a = list(map(int,input().split())) def fact(n): ret = 1 for i in range(1,n+1): ret *= i return ret if min(a) == 0: print(-1) elif max(a) >= 4: print(10**9 + 7) else: ans = 1 for x in a: ans *= x**fact(x) if ans >= 10**9 + 7: print(10**9 + 7) exit() print((10**9 + 7)%ans)