#include<bits/stdc++.h>
using namespace std;
const int sz=1e6+7;
int n;
int low,ans;
char s[sz],t[sz];
int head[26],nxt[sz][26];
deque<int>q;
int main(){
	scanf("%d",&n);
	scanf("%s%s",s+1,t+1);
	bool flag=1;
	for(int i=1;i<=n;i++) if(s[i]!=t[i]) flag=0;
	if(flag) return printf("0\n"),0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<26;j++) nxt[i][j]=head[j];
		head[s[i]-'a']=i;
	}
	for(int j=0;j<26;j++) nxt[n+1][j]=head[j];
	int lst=n+1;
	for(int r=n,l;r>=1;r=l-1){
		l=r;
		while(t[l-1]==t[r]) l--;
		int now=nxt[min(l+1,lst)][t[r]-'a'];
		if(!now) return printf("-1\n"),0;
		low++;
		q.push_front(now+low);
		while(!q.empty()&&q.back()-low>=l) q.pop_back();
		ans=max(ans,(int)q.size()+1);
		lst=now;
	}
	printf("%d\n",ans);
}