#include <bits/stdc++.h>

using namespace std;

const int MX = 1000005;

vector<int> pos[26];
int n;
char sr[MX], tr[MX];

void input()
{
	scanf("%d", &n);
	scanf("%s", sr+1);
	scanf("%s", tr+1);
}

void fucked()
{
	puts("-1");
	exit(0);
}

int que[MX];

void work()
{
	int h, t, ans = 0, pos = n;
	if(strcmp(sr+1, tr+1) == 0) puts("0"), exit(0);
	t = 1, h = 0;
	for(int i=n; i>=1; i--)
	{
		if(tr[i] == tr[i-1]) continue;
		if(i < pos) pos = i;
		while(pos && tr[i]!=sr[pos]) pos--;
		if(!pos) {puts("-1"); return;}
		while(h>=t && que[t]-(h-t)>i) t++;
		que[++h] = pos;
		if(i != pos) ans = max(ans, h-t+1);
	}
	printf("%d\n", ans+1);
}

int main()
{
	input();
	work();
	return 0;
}