from math import factorial n = int(input()) a = list(map(int, input().split())) a.sort() if 0 in a: exit(print(-1)) ans = 1 for i in range(n): if a[i] >= 18: exit(print(10 ** 9 + 7)) ans *= pow(a[i], factorial(a[i])) if ans >= 10 ** 9 + 7: exit(print(10 ** 9 + 7)) print((10 ** 9 + 7) % ans)