import math def main(): N = int(input()) A = list(map(int, input().split())) mod = 10 ** 9 + 7 if 0 in A: return -1 for a in A: if a >= 4: return mod ans = 1 for a in A: ans *= a ** math.factorial(a) return mod % ans print(main())