#include<bits/stdc++.h>
#define N 1000009
using namespace std;

int n,q[N]; char s1[N],s2[N];
int main(){
	scanf("%d%s%s",&n,s1+1,s2+1);
	if (!strcmp(s1+1,s2+1)){
		puts("0"); return 0;
	}
	int i,j,head=1,tail=0,ans=0;
	for (i=j=n; i; i--) if (s2[i]!=s2[i-1]){
		j=min(i,j);
		for (; j && s1[j]!=s2[i]; j--);
		if (!j){
			puts("-1"); return 0;
		}
		while (head<=tail && i<q[head]-(tail-head)) head++;
		if (i!=j) q[++tail]=j;
		ans=max(ans,tail-head+1);
	}
	printf("%d\n",ans+1);
	return 0;
}
