P = 10 ** 9 + 7 n = int(input()) a = list(map(int, input().split())) if 0 in a: print(-1) exit() now = 1 for x in a: x0 = x t = 1 while x: t *= x if t > P: print(P) exit() x -= 1 while t: now *= x0 if now > P: print(P) exit() t -= 1 print(P % now)