#include using namespace std; #define sorted(a) sort(a.begin(), a.end()); typedef long long signed int ll; bool isPrime(ll n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; double sqrtn = sqrt(n); for (int i = 3; i <= sqrtn; i += 2) { if (n % i == 0) return false; } return true; } int main(void) { #ifdef DEBUG freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = -1; ll n; do { n = 0; for (int i = 0; i < N; i++) { n = n * pow(10, to_string(A[i]).length()) + A[i]; } if (isPrime(n)) { ans = max(ans, n); } } while (next_permutation(A.begin(), A.end())); cout << ans << endl; return 0; }