#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
using std::cin; using std::cout;
using std::endl;
using std::bitset; using std::map;
using std::queue; using std::priority_queue;
using std::set; using std::string;
using std::stringstream; using std::vector;
using std::pair; using std::make_pair;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<ULL, ULL> puu;
#ifdef DEBUG
using std::cerr;
#define pass cerr << "[" << __FUNCTION__ << "] : line = " << __LINE__ << endl;
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)                      \
	{                                           \
		cerr << #a << " = {";                   \
		for (int qwq = (st); qwq <= (n); ++qwq) \
			if (qwq == (st))                    \
				cerr << a[qwq];                 \
			else                                \
				cerr << ", " << a[qwq];         \
		cerr << "}" << endl;                    \
	}
#define displayv(a) displaya(a, 0, (int)(a.size() - 1))
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#include <ctime>
class MyTimer {
	clock_t st;
public:
	MyTimer() { cerr << std::fixed << std::setprecision(0); reset(); }
	~MyTimer() { report(); }
	void reset() { st = clock_t(); }
	void report() {  cerr << "Time consumed: " << (clock() - st) * \
		1e3 / CLOCKS_PER_SEC << "ms" << endl; }
} myTimer;
#else
#define cerr if(false) std::cout
#define pass ;
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(a) ;
#define eprintf(...) if(0) fprintf(stderr, __VA_ARGS__)
class MyTimer {
public: void reset() {} void report() {}
} myTimer;
#endif

template<typename A, typename B>
std::ostream& operator << (std::ostream &cout, const pair<A, B> &x) {
	return cout << "(" << x.first << ", " << x.second << ")";
}
template<typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) { return a > b ? a = b, true : false; }
template<typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) { return a < b ? a = b, true : false; }

const int maxN = 1000000 + 233;
int n;
char s[maxN], t[maxN];

bool zero() {
	for(int i = 1; i <= n; ++ i) if(s[i] != t[i]) return false;
	return true;
}

bool one() {
	for(int i = 1; i <= n; ++ i) {
		if(s[i] != s[i - 1] && s[i] != t[i]) return false;
	}
	return true;
}


int solve() {
	std::deque<int> q;
	int pos = n;
	int ans = 0;
	int delta = 0;
	for(int i = n; i >= 1; -- i) if(t[i] != t[i - 1]) {
		chmin(pos, i);
		while(pos > 1 && s[pos] != t[i]) -- pos;
		if(s[pos] != t[i]) return -1;
		while(q.size() && q.back() + delta > i) q.pop_back();
		if(i == pos) {
			chmax(ans, 1);
		} else {
			delta -= 1; q.push_front(pos - delta);
			chmax(ans, (int)q.size() + 1);
		}
//		display(i); display(delta);
//		displayv(q);
	}
	return ans;
}

int main() {
	std::ios::sync_with_stdio(false);
	cin >> n >> (s + 1) >> (t + 1);
	if(zero()) cout << "0" << endl;
//	else if(one()) cout << "1" << endl;
	else {
		cout << solve() << endl;
	}
	return 0;
}


Measured memory_bytes: 6272