#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

int n, ans;
string s, t;
queue<int> q;

int main()
{
	cin >> n >> s >> t;
	
	if (s == t)
	{
		puts("0");
		return 0;
	}
	
	int up = n - 1, down = n - 1;
	
	while (down >= 0)
	{
		while (down && t[down - 1] == t[down]) --down;
		while (up >= 0 && (up > down || s[up] != t[down])) --up;
		if (up < 0)
		{
			puts("-1");
			return 0;
		}
		while (!q.empty() && q.front() - q.size() >= down) q.pop();
		q.push(up);
		if (up != down) ans = max(ans, (int)q.size());
		--down;
	}
	
	cout << ans + 1;
	
	return 0;
}