#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <queue>
using namespace std;
inline int read()
{
	int f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}
const int N = 1e6;

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

int main()
{
	n = read();
	cin >> s;
	cin >> t;

	if (s == t) {
		printf("0\n");
		return 0;
	}
	int from = n - 1, to = n - 1;
	while (to >= 0) {
		while (to && t[to - 1] == t[to])
			to--;
		while (from >= 0 && (s[from] != t[to] || from > to))
			from--;
		if (from < 0) {
			printf("-1\n");
			return 0;
		}
		while (!q.empty() && to + q.size() <= q.front())
			q.pop();
		if (from != to)
			q.push(from);
		if (q.size() + 1 > ans)
			ans = (q.size() + 1);
		to--;
	}

	printf("%d\n", ans);
	return 0;
}
