def main(): from sys import stdin import math readline=stdin.readline n = int(readline()) A = list(map(int, readline().split())) mod = 10**9 + 7 ans = 1 for a in A: if a == 0: print(-1) exit() if a >= 4: print(mod) exit() ans *= pow(a,math.factorial(a)) print(mod % ans) main()