#include <bits/stdc++.h>

const int N = 1000005;

int n, ans = 1;
std::string s, t;
std::queue<int> q;

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> s >> t;
	if (s == t) return std::cout << "0\n", 0;
	for (int i = n - 1, k = n - 1; ~i; --i) if (!i || t[i] != t[i - 1]) {
		k = std::min(k, i); while (~k && s[k] != t[i]) --k;
		if (k < 0) return std::cout << "-1\n", 0;
		if (i == k) {while (q.size()) q.pop(); continue;}
		while (q.size() && q.front() - q.size() >= i) q.pop();
		q.push(k), ans = std::max(ans, (int) q.size() + 1);
	}
	std::cout << ans << '\n';
	return 0;
}