import math MOD = 10**9 + 7 n = int(input()) a = list(map(int, input().split())) if any(v == 0 for v in a): print(-1) exit() if max(a) > 3: print(MOD) exit() else: ans = 1 for v in a: ans *= pow(v, math.factorial(v)) if ans > MOD: print(MOD) exit() print(MOD % ans) exit()