from collections import defaultdict import sys readline=sys.stdin.readline N=int(readline()) A=list(map(int,readline().split())) mod=10**9+7 if any(a>=4 for a in A): ans=mod elif any(a==0 for a in A): ans=-1 else: x=1 for a in A: if a==1: x*=1 elif a==2: x*=2**2 else: x*=3**6 if x>=mod: ans=mod break else: ans=mod%x print(ans)