#pragma GCC optimization ("O3") #include using namespace std; using ll = long long; using vec = vector; using mat = vector; using pll = pair; using dvec = vector; using dmat = vector; #define INF (1LL<<61) #define MOD 1000000007LL //#define MOD 998244353LL #define PR(x) cout << (x) << endl #define PS(x) cout << (x) << " " #define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i)) #define FORE(i,v) for(auto (i):v) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((ll)(x).size()) #define REV(x) reverse(ALL((x))) #define ASC(x) sort(ALL((x))) #define DESC(x) {ASC((x)); REV((x));} #define BIT(s,i) (((s)>>(i))&1) #define pb push_back #define fi first #define se second template inline int chmin(T& a, T b) {if(a>b) {a=b; return 1;} return 0;} template inline int chmax(T& a, T b) {if(a=MOD) x-=MOD; return *this;} mint& operator-=(const mint& a) {if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;} mint& operator*=(const mint& a) {(x*=a.x)%=MOD; return *this;} mint operator+(const mint& a) const {mint b(*this); return b+=a;} mint operator-(const mint& a) const {mint b(*this); return b-=a;} mint operator*(const mint& a) const {mint b(*this); return b*=a;} mint pow(ll t) const {if(!t) return 1; mint a=pow(t>>1); return (t&1?*this*a:a)*a;} mint inv() const {return pow(MOD-2);} mint& operator/=(const mint& a) {return *this*=a.inv();} mint operator/(const mint& a) const {mint b(*this); return b/=a;} }; istream &operator>>(istream& is, mint& a) {ll t; is>>t; a=t; return is;} ostream &operator<<(ostream& os, const mint& a) {return os<; using mmat = vector; ll modpow(ll a, ll n, ll m) { if(n == 0) return 1; ll t = modpow(a, n/2, m); t = (ll)((__int128)t*t%m); if(n%2) t = (ll)((__int128)t*a%m); return t; } bool miller_rabin(ll n) { if(n <= 1) return false; if(n == 2) return true; if(n > 2 && n%2 == 0) return false; ll s = 0, t = n-1; while(t%2 == 0) ++s, t /= 2; ll a = rand()%(n-1)+1; if(modpow(a, t, n) == 1) return true; REP(i,0,s) { if(modpow(a, modpow(2, i, INF)*t, n) == n-1) return true; } return false; } int main() { ll N; cin >> N; vec A(N); REP(i,0,N) cin >> A[i]; ASC(A); ll ans = -1; srand(time(NULL)); do { string s; REP(i,0,N) s += to_string(A[i]); ll p = stoll(s); bool f = true; REP(i,0,50) f &= miller_rabin(p); if(f) chmax(ans, p); } while(next_permutation(ALL(A))); PR(ans); return 0; } /* */