from math import factorial n = int(input()) a = [int(i) for i in input().split()] if max(a) >= 4: print(-1) exit() ans = 1 mod = 10 ** 9 + 7 for i in a: ans *= pow(i, factorial(i)) if ans >= mod: print(-1) exit() print(mod % ans)