from math import factorial MOD = 10**9 + 7 N = int(input()) A = list(map(int,input().split())) ans = 1 for e in A: if e > 10: print(MOD) exit(0) elif e != 0: ans *= pow(e,factorial(e),MOD) if ans > MOD: print(MOD) exit(0) print(-1 if ans == 0 else MOD%ans)