#include <bits/stdc++.h>
#define rep
using namespace std;

const int maxn = 1e6;
int n;
char s[maxn + 5], t[maxn + 5];

int main() {
	scanf("%d %s %s", &n, s + 1, t + 1);
	bool fl = true;
	for (int i = 1; i <= n; i++) fl &= s[i] == t[i];
	if (fl) puts("0"), exit(0);
	queue<int> Q;
	int ans = 0;
	for (int i = n, j = n; i; i--, j--) {
		while (t[i] == t[i - 1]) i--;
		while (j && (j > i || s[j] != t[i])) j--;
		if (!j) puts("-1"), exit(0);
		while (!Q.empty() && i <= Q.front() - Q.size()) Q.pop();
		if (i != j) Q.push(j);
		ans = max(ans, (int)Q.size() + 1);
	}
	printf("%d\n", ans);
	return 0;
}