#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 1000005
char s[maxn],t[maxn];
int n,cnt,ans;
struct Vergil
{
	int x,y;	
}a[maxn],b[maxn];

bool comp(char *s,char *t) 
{
	for (int i=1;i<=n;i++) 
		if (s[i]!=t[i])	return 0;
	return 1;
}

bool check(int x)
{
	for (int i=1;i<=cnt-x;i++)
		if (b[i+x].x-x<b[i].y) return 0;
	return 1;
}

int main()
{
	scanf("%d",&n);
	scanf("%s%s",s+1,t+1);
	if (comp(s,t)) {puts("0");return 0;}
	for (int i=n,j=n;i>=1;i--) 
	{
		j=min(j,i);
		while (j>0&&s[j]!=t[i]) j--;	
		if (j==0) {puts("-1");return 0;}
		a[i]=(Vergil){j,i};
	}
	b[1]=a[1];cnt=1;
	for (int i=2;i<=n;i++) 
		if (a[i].x==a[i-1].x) b[cnt]=a[i];
		else b[++cnt]=a[i];
	int L=1,R=cnt;
	while (L<=R) 
	{
		int mid=(L+R)>>1;
		if (check(mid))	{ans=mid;R=mid-1;}
		else L=mid+1;
	}
	printf("%d\n",ans);
	return 0;	
}
