bool isprime(ll x){ if (x <= 1) return false; if (x == 2) return true; if (x%2 == 0) return false; for (ll d = 3; d*d <= x; d+=2) if (x/d*d == x) return false; return true; } ll next_perm(vector& buckets, ll val = 0) { bool empt = true; ll best = -1; REP(i, 13){ if (buckets[i] == 0) continue; buckets[i]--; if (i <= 8) best = max(best, next_perm(buckets, val*10+(i+1))); else best = max(best, next_perm(buckets, val*100+(i+1))); buckets[i]++; empt = false; } if (empt) return isprime(val) ? val : -1; else return best; } int N; { vector buckets; rd(N); buckets.resize(13); REP(i, N){ int a; rd(a); buckets[a-1]++; } ll ans; ans = next_perm(buckets); wt(ans); }