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