//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>

using namespace std;  typedef long long ll;
int n,ans;
const int maxn=1e6+5;
char S[maxn],T[maxn];
deque<int> q;
int main(){
	scanf("%d%s%s",&n,S+1,T+1);
	q.push_back(n+1);
	for(int t=n,p=n+1,offset=0;t;--t){
		int sav=p;
		while(p&&(p>t||S[p]!=T[t])) --p;
		if(p<1) puts("-1"),exit(0);
		if(sav==p){
			while(q.size()&&q.back()-offset>=t) q.pop_back();
			q.push_back(t+offset);
		}else{
			++offset;
			if(t!=p) ans=max(ans,(int)q.size()),q.push_front(p+offset);
		}
	}
	cout<<ans<<endl;
	return 0;
}
