import math n = int(input()) a = list(map(int,input().split())) if min(a) == 0: print(-1) exit() elif max(a) >= 4: print(((10)**9)+7) exit() else: ans = 1 for i in range(n): tmp = math.factorial(a[i]) ans *= a[i]**tmp if ans >= ((10)**9)+7: print((10**9)+7) exit() print(((10**9)+7)%ans)