#include "bits/stdc++.h" using namespace std; typedef long long ll; #define rep(i,l,r) for(int i=(l);i<(r);i++) #define fcout cout << fixed << setprecision(10) array card; ll mulmod(ll a, ll b, ll mod) { ll x = 0,y = a % mod; while (b > 0) { if (b % 2 == 1) { x = (x + y) % mod; } y = (y * 2) % mod; b /= 2; } return x % mod; } /* * modular exponentiation */ ll modulo(ll base, ll exponent, ll mod) { ll x = 1; ll y = base; while (exponent > 0) { if (exponent % 2 == 1) x = (x * y) % mod; y = (y * y) % mod; exponent = exponent / 2; } return x % mod; } /* * Miller-Rabin primality test, iteration signifies the accuracy */ bool Miller(ll p,int iteration) { if (p < 2) { return false; } if (p != 2 && p % 2==0) { return false; } ll s = p - 1; while (s % 2 == 0) { s /= 2; } for (int i = 0; i < iteration; i++) { ll a = rand() % (p - 1) + 1, temp = s; ll mod = modulo(a, temp, p); while (temp != p - 1 && mod != 1 && mod != p - 1) { mod = mulmod(mod, mod, p); temp *= 2; } if (mod != p - 1 && temp % 2 == 0) { return false; } } return true; } bool is_prime(ll n){ if (n < 2) return false; if (n < 4) {cout << n; return true;} if (!(n % 2)) return false; if (!(n % 3)) return false; ll sq = sqrt(n); for(int i = 5 ;i < 64; i += 4 - i % 6 / 2){ if (sq < i) {cout << n; return true;}; if (!(n % i)) return false; } return Miller(n, 50); } ll putBack(ll a, int b){ return a * (b < 10 ? 10 : 100) + b; } bool ans(int n, ll cnt){ if(!n){ if(is_prime(cnt)) return true; else return false; } if(n == 1) rep(i, 1, 14) if(card[i]){ if(ans(n - 1, putBack(cnt, i))) return true; else return false; } for(int i = 9 ; i > 1 ; i--)if(card[i]){ card[i]--; if(ans(n - 1, putBack(cnt, i))) return true; card[i]++; } if(card[1]){ card[1]--; for(int i = 9 ; i > 3 ; i--)if(card[i]){ card[i]--; if(ans(n - 2, putBack(cnt, 10 + i))) return true; card[i]++; } card[1]++; } for(int i = 3 ; i > -1 ; i--){ if(card[10 + i]){ card[10 + i]--; if(ans(n - 1, putBack(cnt, 10 + i))) return true; card[10 + i]++; } else if(card[1]){ card[1]--; if(card[i]){ card[i]--; if(ans(n - 2, putBack(cnt, 10 + i))) return true; card[i]++; } card[1]++; } } return false; } int main(){ int n, a; cin >> n; rep(i, 0, n){ cin >> a; card[a]++; } if(!ans(n, 0))cout << -1; }