/** * @FileName a.cpp * @Author kanpurin * @Created 2022.10.10 21:19:24 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; bool MillerRabin(long long N) { if (N <= 1) return false; if (N == 2) return true; if (N % 2 == 0) return false; auto modpow = [](__int128_t a, long long n, long long mo) { __int128_t r = 1; a %= mo; while (n) r = r * ((n % 2) ? a : 1) % mo, a = a * a % mo, n >>= 1; return r; }; vector A = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; long long s = 0, d = N - 1; while (d % 2 == 0) d >>= 1, s++; for (long long a : A) { if (a % N == 0) return true; long long j, r = modpow(a, d, N); if (r == 1) continue; for (j = 0; j < s; j++) { if (r == N - 1) break; r = __int128_t(r) * r % N; } if (j == s) return false; } return true; } int main() { int n; cin >> n; vector< int > a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); ll ans = -1; do { ll num = 0; for (int i = 0; i < n; i++) { if (a[i] >= 10) { num *= 100; num += a[i]; } else { num *= 10; num += a[i]; } } if (ans < num && MillerRabin(num)) ans = max(ans, num); } while (next_permutation(a.begin(), a.end())); cout << ans << endl; return 0; }