n = int(input()) a = list(map(int,input().split())) if 0 in a: print(-1) exit() mod = 10**9+7 count = 1 for i in a: if i >= 4: print(mod) exit() x = 1 for j in range(1,i+1): x *= j count *= pow(i,x) if count > mod: print(mod) exit() print(mod%count)