N = int(input()) A = tuple(map(int, input().split())) DIV = 10 ** 9 + 7 if 0 in A: print(-1) exit() def excess(flag): if flag: print(DIV) exit() ans = 1 for a in A: excess(a >= 4) tmp = 1 for i in range(1, a + 1): tmp *= i ans *= a ** tmp excess(ans > DIV) print(DIV % ans)