#yuki1237 import math mod=10**9+7 n=int(input()) l=list(map(int,input().split())) if 0 in l: print(-1) exit() if max(l)>3: print(mod) res=1 for i in l: x=math.factorial(i) y=pow(i,x) res*=y if res>=mod: print(mod) exit() print(mod%res)