import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) A=[int(i) for i in input().split()] mod=10**9+7 if max(A)>=4: print(mod) elif min(A)==0: print(-1) else: F=[1,1,2,6] cur=1 for a in A: cur*=pow(a,F[a]) if cur>mod: print(mod) break else: print(mod%cur)