#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

const int MAXN = 1000000 + 1000;

int n;
char s[MAXN], t[MAXN];

void no()
{
	cout << -1 << endl;
	exit(0);
}

vector<int> sp, ri;

void init()
{
	int p = n;
	for(int i = n; i >= 1; i--)
		if(i == n || t[i] != t[i + 1] || i == p)
		{
			ri.push_back(i);
			while(p >= 1 && s[p] != t[i])
				p--;
			if(p <= 0) no();
			sp.push_back(p);
			p = p - 1;
			// cout << i << ' ' << p << endl;
		}
	reverse(sp.begin(), sp.end());
	reverse(ri.begin(), ri.end());
	sp.push_back(n + 1), ri.push_back(n + 1);
	// for(int i = 0; i < sp.size(); i++)
	// 	cout << sp[i] << ' ' << ri[i] << endl;	
}

void solve()
{
	if(strcmp(s + 1, t + 1) == 0)
	{
		cout << 0 << endl;
		exit(0);
	}
	int ans = 0;
	int pos = 0, cnt = 0;
	for(int i = 0; i < sp.size() - 1; i++)
	{
		if(cnt > 0) cnt--;
		while(i + cnt < sp.size() && sp[i + cnt] - cnt < ri[i])
			cnt++;
		ans = max(ans, cnt);
		// cout << cnt << endl;
	}
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("game.in", "r", stdin);
	// freopen("game.out", "w", stdout);

	cin >> n;
	cin >> (s + 1);
	cin >> (t + 1);

	init();
	solve();

	return 0;
}
/*
12
abxxcdefghij
aabbbbccdeee
*/
/*
8
bbaabbxx
bbbbbbba
*/
/*
10
cydjgcbckr
cccdggggcc
*/
/*
10
aaaaaaaa
aaaaaaaa
*/

#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1001000 
#define pb push_back 
int n,ans,pos[N],sum[N];
char s[N],p[N];
vector<int>ve[30];
vector<int>::iterator it;
int p1[N],p2[N],m;
bool check(int x)
{
	for(int i=1;i+x<=m;++i)
		if(p1[i+x]-x<p2[i])
			return false;
	return true;
}
int main()
{
	scanf("%d%s%s",&n,s+1,p+1);
	int i,last=n+1,flag=0,r;
	for(i=1;i<=n;++i) if(s[i]!=p[i]) flag=1;
	if(!flag) puts("0");
	else
	{
		flag=0;
		for(i=1;i<=n;++i) ve[s[i]-'a'].pb(i);
		for(r=i=n;i>=1;--i)
		{
			if(i==1||p[i-1]!=p[i])
			{
				last=min(last,i+1);
				it=lower_bound(ve[p[i]-'a'].begin(),ve[p[i]-'a'].end(),last);
				if(it==ve[p[i]-'a'].begin()) {flag=1; break;}
				--it;
				last=*it;
				++m;
				p1[m]=*it; p2[m]=r;
				r=i-1;
			}
		}
		if(flag) puts("-1");
		else
		{
			for(i=1;i<=m;++i) if(i<m+1-i) swap(p1[i],p1[m+1-i]),swap(p2[i],p2[m+1-i]);
			int l=0,mid; r=m;
			while(l<r)
			{
				mid=(l+r)>>1;
				if(check(mid)) r=mid;
				else l=mid+1;
			}
			printf("%d",r);
		}
	}
	return 0;
}