import math N = int(input()); MOD = pow(10,9)+7 A = list(map(int,input().split())) if 0 in A: print(-1);exit() if min(A) >= 4: print(MOD);exit() ans = 1 for x in A: kata = math.factorial(x) temp = pow(x,kata) ans = ans*temp print(MOD%ans)