from sys import stdin import math mod = 10**9+7 N = int(input()) A = list(map(int,stdin.readline().split())) now = 1 for i in A: if i > 10 or now > 10**9+7: print (10**9+7) sys.exit() now *= i ** math.factorial(i) ans = mod % now if ans == 0: print (-1) else: print (ans)