import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; import java.math.*; import java.util.*; import java.io.*; public class y774 { public static void main(String[] args) { new y774().run(); } Scanner in = new Scanner(System.in); void _out(Object...os) { System.out.println(deepToString(os)); } void _err(Object...os) { System.err.println(deepToString(os)); } int N; int[] A; int[] work; void run() { for (; in.hasNext(); ) { N = in.nextInt(); A = new int[N]; for (int i = 0; i < N; ++i) { A[i] = in.nextInt(); } sort(A); work = new int[N]; BigInteger ans = valueOf(-1); do { if (N >= 2 && (A[N - 1] % 2 == 0 || A[N - 1] % 5 == 0)) { continue; } String str = ""; for (int i = 0; i < N; ++i) { str += Integer.toString(A[i]); } BigInteger x = new BigInteger(str); if (ans.compareTo(x) < 0) { if (x.isProbablePrime(100)) { ans = x; } } } while (nextPermutation()); System.out.println(ans); } } boolean nextPermutation() { for (int i = N - 2; i >= 0; --i) { if (A[i] < A[i + 1]) { for (int j = N - 1; j > i; --j) { if (A[i] < A[j]) { int workLen = 0; work[workLen++] = A[j]; for (int k = N - 1; k > j; --k) { work[workLen++] = A[k]; } work[workLen++] = A[i]; for (int k = j - 1; k > i; --k) { work[workLen++] = A[k]; } for (int k = i; k < N; ++k) { A[k] = work[k - i]; } return true; } } } } return false; } }