N=int(input()) A=list(map(int,input().split())) F=[1,1,2,6] P=1 for i in range(N): if A[i]>3: print(10**9+7) exit() P*=pow(A[i],F[A[i]]) if P>10**9+7: print(10**9+7) exit() if P==0: print(-1) exit() print((10**9+7)%P)