#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; // オーバーフローしないけど、vsでは使えない ll powMod(__int128 n, ll k, ll mod) { if (n == 0)return 0; __int128 res = 1; while (k) { if (k & 1)res = res*n%mod; n = n*n%mod; k >>= 1; } return res; } bool MillerRabinPrimalityTest(ll n, int precision = 20) { static mt19937_64 mt64; if (n == 2)return true; if (n == 1 || n % 2 == 0)return false; ll q = n - 1, k = 0; while (!(q & 1)) { q >>= 1; k++; } uniform_int_distribution unirand(1, n - 1); for (int i = 0; i < precision; ++i) { ll a = unirand(mt64); ll aq = powMod(a, q, n); if (aq == 1)continue; bool flag = true; for (int j = 0; j < k; ++j) { if (powMod(aq, (1ll << j), n) == n - 1) { flag = false; break; } } if (flag)return false; } return true; } void solve() { int N; cin >> N; vector S(N); rep(i, N) { cin >> S[i]; } ll ans = -1; sort(all(S)); do { string t = ""; each(s, S)t += s; ll n = stoll(t); if (n > ans && MillerRabinPrimalityTest(n)) { ans = n; } } while (next_permutation(all(S))); cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }