#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const long long infll = (long long)1.01e18;
const long double eps = 1e-9;
const long double pi = acos((long double)-1);
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
void precalc() {}
const int maxn = (int)2e6 + 5;
int n;
string s, t;
char tmp[maxn];
bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  scanf("%s", tmp);
  s = tmp;
  scanf("%s", tmp);
  t = tmp;
  return true;
}
int toadd[maxn];
bool check(int h) {
  memset(toadd, 0, sizeof(toadd));
  int val = 0;
  int pos = 0;
  for (int i = 0, k = 0; i < n;) {
    int j = i;
    while (j < n && t[j] == t[i]) {
      j++;
    }
    while (k <= i && (s[k] != t[i] || val + 1 > h)) {
      k++;
      pos++;
      val += toadd[pos];
    }
    if (k > i) {
      return false;
    }
    val++;
    k++;
    toadd[pos + j - k]--;
    if (j == k) {
      val--;
    }
    i = j;
  }
  return true;
}
void solve() {
  if (s == t) {
    printf("0\n");
    return;
  }
  if (!check(n)) {
    printf("-1\n");
    return;
  }
  int l = 0, r = n;
  while (l < r - 1) {
    int m = (l + r) / 2;
    if (check(m)) {
      r = m;
    } else {
      l = m;
    }
  }
  printf("%d\n", r);
}
int main() {
  precalc();
  while (read()) {
    solve();
  }
  return 0;
}
