#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; vector sieve(int n){ vector f(n+1); for(int i=3; i<=n; i+=2) f[i] = 1; for(int i=3; i<=sqrt(n); i+=2) if(f[i]) for(int j=i*3; j<=n; j+=i) f[j] = 0; vector res{0, 2}; for(int i=3; i<=n; i+=2) if(f[i]) res.push_back(i); res.push_back(n+1); return res; } const int MA = 5000000, SA = 348515; int N, A[10], sum[10][SA + 1], flag[10]; int main(){ cin >> N; rep(i, N)cin >> A[i], flag[A[i]] = 1; auto ps = sieve(MA); int m = sz(ps); rep(i, m){ int p = ps[i]; while(p > 0){ sum[p % 10][i+1]++; p /= 10; } } rep(i, 10)rep(j, SA)sum[i][j + 1] += sum[i][j]; vi no, use; rep(i, 10)(flag[i] ? use : no).push_back(i); int r = 1, ans = -1; for(int l = 1; l < m; ++l){ int okok = 1; each(ng, no)if(sum[ng][l + 1] - sum[ng][l]){ okok = 0; break; } if(!okok)continue; smax(r, l); while(r