import sys import itertools import math def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) n = I() a = LI() if min(a) == 0: print(-1) elif max(a) >= 4: print(10**9+7) elif a.count(3) >= 4: print(10**9+7) elif a.count(2) >= 16: print(10**9+7) else: ans = 1 for i in range(n): if a[i] == 2: ans *= 2**2 elif a[i] == 3: ans *= 3**6 print((10**9+7)%ans)