#include <bits/stdc++.h>
using namespace std;
#define sorted(a) sort(a.begin(), a.end());
typedef long long signed int ll;

const vector<unsigned int> numset = {2,3,5,7,11,13,17,19,23,29,31,37};
unsigned long long mod_pow(unsigned __int128 x, unsigned long long k, unsigned long long mod) {
  unsigned __int128 res = 1;
  while (k) {
    if (k & 1) res = res * x % mod;
    x = x * x % mod;
    k >>= 1;
  }
  return res;
}

bool isPrime(unsigned long long n) {
  if (n < 2) return false;
  unsigned long long d = n - 1, s = 0;
  while(d % 2 == 0){
    d /= 2;
    s++;
  }
  for(unsigned int a : numset) {
    if (a == n) return true;
    unsigned long long res = mod_pow(a, d, n);
    if (res == 1) continue;
    bool ok = true;
    for (unsigned int r = 0; r < s; r++) {
      if (res == n-1) {
        ok = false;
        break;
      }
      res = (__int128)res * res % n;
    }
    if (ok) 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<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll ans = -1;
  ll n, l;
  do {
    n = 0;
    for (int i = 0; i < N; i++) {
      l = pow(10, to_string(A[i]).length());
      n = n * l + A[i];
    }
    if (isPrime(n)) {
      ans = max(ans, n);
    }
  } while (next_permutation(A.begin(), A.end()));
  cout << ans << endl;

  return 0;
}