#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}
int func(int n)
{
    return (n*(n+1))/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
   string str;
   cin>>str;
   set<char> s;
   for(int i=0;i<str.length();i++)
   {
      s.insert(str[i]);
   }
   if(s.size()==26)
    cout<<"None";
  else
  { int i=0;

    for(auto it=s.begin();it!=s.end();it++,i++)
    {

        if(*it!=(97+i))
        {
            
            cout<<(char)(97+i);
            return 0;
        }
    }
    if(s.size()<26)
    {
        cout<<char(97+s.size());
    }
  }


 return 0;
}







//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define mxlen 1000+9
#define inf 1000009
#define INF (int)1e9
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;

char s1[inf],s2[inf];
int q[inf*2],head=inf,tail=inf-1;

int main(){
	int n;
	rd(n)
	scanf("%s%s",&s1,&s2);
	q[++tail]=n+1;
	int pos=n+1,cnt=0,ans=0;
	for (int i=n;i>=1;i--){
		int tmp=pos;
		while (pos>0 && (pos>i || s1[pos-1]!=s2[i-1])){
			pos--;
		}
		if (pos==0){
			puts("-1");
			return 0;
		}
		if (tmp==pos){
			while (head<=tail && q[tail]-cnt>=i){
				tail--;
			}
			q[++tail]=i+cnt;
		}
		else{
			cnt++;
			if (i!=pos){
				ans=max(ans,tail-head+1);
				q[--head]=pos+cnt;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}