#include <bits/stdc++.h>
using namespace std;
deque<int> dq;
int n, ans;
char str1[1000001], str2[1000001];
int main() {
  scanf("%d%s%s", &n, str1 + 1, str2 + 1);
  dq.push_back(n + 1);
  for (int i = n, j = n + 1, d = 0; i; --i) {
    int t = j;
    j = min(i, j);
    while (j && str1[j] != str2[i]) --j;
    if (j < 1) puts("-1"), exit(0);
    if (t == j) {
      while (!dq.empty() && dq.back() + d >= i) dq.pop_back();
      dq.push_back(i - d);
    } else {
      --d;
      if (i != j) ans = max(ans, (int)dq.size()), dq.push_front(j - d);
    }
  }
  printf("%d", ans);
}
