# coding: utf-8 # Your code here! N=int(input()) A=list(map(int,input().split())) ans=1 mod=(10**9+7) for a in A: if a>=4: ans*=(mod+1) elif a==3: ans*=3**6 elif a==2: ans*=2**2 if ans>mod: print(mod) exit() if ans==1: print(-1) else: print(mod%ans)