#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int ans,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;
	}
	for (int i=n,j=n,l=1,r=0;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 (l<=r&&i<q[l]-(r-l))l++;
			if (i!=j)q[++r]=j;
			ans=max(ans,r-l+1);
		}
	printf("%d\n",ans+1);
	return 0;
}
