#include using namespace std; bool isp(long n) { if (n < 2) return false; long s = __builtin_ctzl(n - 1), d = n >> s; for (auto b : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { long p = 1, i = s, j = d, k = b; while (j > 0) { if (j & 1) p = (__int128) p * k % n; k = (__int128) k * k % n; j >>= 1; } while (p != 1 && p != n - 1 && b % n && i--) p = (__int128) p * p % n; if (p != n - 1 && i != s) return false; } return true; } int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) cin >> A.at(i); vector V; sort(A.begin(), A.end()); do { string tmp; for (auto a : A) tmp += a; V.push_back(stol(tmp)); } while (next_permutation(A.begin(), A.end())); sort(V.rbegin(), V.rend()); for (auto v : V) if (isp(v)) return cout << v << "\n", 0; cout << -1 << "\n"; }