#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 1e6 + 10;
int n, ans;
string s, t;
queue<int> q;

int main() {
    cin >> n >> s >> t;
    if (s == t) return puts("0"), 0;
    int up = n - 1, down = n - 1;
    while (down >= 0) {
        while (down && t[down - 1] == t[down]) --down;
        while (up >= 0 && (up > down || s[up] != t[down])) --up;
        if (up < 0) return puts("-1"), 0;
        while (q.size() && q.front() - q.size() >= down) q.pop();
        if (up != down) q.push(up);  // 折线真的是折的，而不是直接竖下来
        ans = max(ans, (int)q.size() + 1);
        --down;
    } printf("%d\n", ans);
    return 0;
}
