def isprime(n): if n <= 1: return False elif n == 2: return True elif n % 2 == 0: return False A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022] s = 0 d = n - 1 while d % 2 == 0: s += 1 d >>= 1 for a in A: if a % n == 0: return True x = pow(a, d, n) if x != 1: for t in range(s): if x == n - 1: break x = x * x % n else: return False return True n = int(input()) A = list(map(int, input().split())) B = [0] * n for i in range(n): if A[i] < 10: B[i] = 10 else: B[i] = 100 ans = -1 used = [False] * n memo = set() def dfs(t, x): if t == n: global ans if x > ans and isprime(x): ans = x return if x in memo: return memo.add(x) for i in range(n): if not used[i]: used[i] = True dfs(t + 1, x * B[i] + A[i]) used[i] = False dfs(0, 0) print(ans)