#include using namespace std; //#define int long long typedef long long ll; typedef pairpint; typedef vectorvint; typedef vectorvpint; #define pb push_back #define mp make_pair #define fi first #define se second #define ln <void chmin(T &t,U f){if(t>f)t=f;} templatevoid chmax(T &t,U f){if(t>s; rep(j,s.size())ex[i][s[j]-'0']=1; } cin>>N; rep(i,N){ int a;cin>>a;ok[a]=1; } int l=1; int ans=-1; reps(i,1,p.size()-1){ rep(j,10)cnt[j]+=ex[i][j]; while(l<=i&&!check()){ rep(j,10)cnt[j]-=ex[l][j]; l++; } bool y=true; rep(j,10)y&=!((cnt[j]!=0)^ok[j]); if(y){ int hoge=p[l-1]+1; int piyo=p[i+1]-1; chmax(ans,piyo-hoge); } } cout<