#include using namespace std; template void chmax(T &a,T b){ if(a F[5000001]; int P[5000001]; bool prime(int a){ if(~P[a])return P[a]; for(int i=2;i*i<=a;i++)if(a%i==0)return P[a]=0; return P[a]=1; } vector f(int a){ if(F[a].size())return F[a]; int tmp=a; vector res; while(a){ res.push_back(a%10); a/=10; } return F[tmp]=res; } signed main(){ memset(P,-1,sizeof(P)); int n;cin>>n; int ans=0; vector v(10,0),now(10,0); while(n--){int a;cin>>a;v[a]++;} for(int l=1,r=1;r<=5000000;r++){ if(prime(r)){ for(int p:f(r))now[p]++; while(true){ bool fl=false; for(int i=0;i<10;i++)if((!v[i])&&now[i])fl=1; if(fl){ while(!prime(l))l++; for(int p:f(l))now[p]--; l++; } else break; } } int a=0; for(int i=0;i<10;i++)if((v[i]&&!now[i])||(!v[i]&&now[i]))a=1; if(!a)chmax(ans,r-l); } cout<