import java.math.BigInteger; import java.util.ArrayDeque; import java.util.Deque; import java.util.Scanner; import java.util.stream.IntStream; public class Main { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int n = stdin.nextInt(); String[] a = new String[n]; IntStream.range(0, n).forEach(i -> a[i] = stdin.next()); Deque strs = new ArrayDeque<>(); Deque bits = new ArrayDeque<>(); strs.addLast(""); bits.addLast(0); BigInteger answer = new BigInteger("-1"); while (!strs.isEmpty()) { String str = strs.pollFirst(); int bit = bits.pollFirst(); if (bit == (1 << n) - 1) { BigInteger val = new BigInteger(str); if (val.isProbablePrime(1)) answer = answer.max(val); } else { for (int i = 0; i < n; i++) { if ((bit & (1 << i)) != 0) continue; strs.addLast(str + a[i]); bits.addLast(bit | (1 << i)); } } } System.out.println(answer); } }