#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 int get(vector &c){ int ret = 0; rep(i,10){ if(c[i]>0)ret |= 1< f(5000001,true); f[0] = false; f[1] = false; for(int i=2;i t(f.size(),0); rep(i,f.size()){ if(f[i]){ int x = i; while(x!=0){ t[i] |= 1<<(x%10); x/=10; } } } int N; cin>>N; int tt = 0; rep(i,N){ int x; cin>>x; tt |= 1< cnt(10,0); int l = 1; for(int i=1;i>j)&1)cnt[j]++; } } while((get(cnt)|tt)!=tt){ if(f[l]){ rep(j,10){ if((t[l]>>j)&1)cnt[j]--; } } l++; } if(get(cnt)==tt)ans = max(ans,i-l); } if(ans==0)ans = -1; cout<