N = int(input()) A = tuple(map(int, input().split())) DIV = 10 ** 9 + 7 if 0 in A: print(-1) exit() ans = 1 for a in A: if a >= 4: # 10e9+7を答で割る? print(DIV) exit() for i in range(1, a + 1): ans *= a ** i print(DIV % ans)