import java.util.*; public class Main { static int[] arr; static int n; static boolean[] used; static TreeSet numbers = new TreeSet<>(); public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); arr = new int[n]; used = new boolean[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } make(1, 0, used); for (long x : numbers) { x *= -1; if (isPrime(x)) { System.out.println(x); return; } } System.out.println(-1); } static void make(int count, long value, boolean[] used) { if (count > n) { numbers.add(-value); return; } int prev = 0; for (int i = n - 1; i >= 0; i--) { if (!used[i]) { if (prev == arr[i]) { continue; } prev = arr[i]; used[i] = true; long next; if (arr[i] >= 10) { next = value * 100 + arr[i]; } else { next = value * 10 + arr[i]; } make(count + 1, next, used); used[i] = false; } } } static boolean isPrime(long x) { if (x % 2 == 0) { return false; } for (int i = 3; i <= Math.sqrt(x); i += 2) { if (x % i == 0) { return false; } } return true; } }