#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e6 + 10;
const int INF = 1e9 + 7;
int N;
char S[MAXN], T[MAXN];
int q[MAXN], ql, qr;
int ans;

int main() {
	register int i, j;
	scanf("%d%s%s", &N, S + 1, T + 1);
	j = N; ql = 1, qr = 0;
	bool ok = 1;
	for(i = 1; i <= N; ++i)
		ok &= S[i] == T[i];
	if(ok)
		return puts("0"), 0;
	for(i = N; i; --i) {
		if(T[i] == T[i - 1]) continue;
		j = min(j, i);
		while(j && T[i] != S[j]) --j;
		if(j == 0) return puts("-1"), 0;
		while(ql <= qr) {
			if(q[ql] - (qr - ql + 1) + 1 > i) ++ql;
			else break;
		}
		q[++qr] = j;
		if(i != j) ans = max(ans, (qr - ql + 1));
	}
	printf("%d\n", ans + 1);
	return 0;
}
