#include <bits/stdc++.h>
using namespace std;
int n, cnt;
string s, t;
vector<int> pos[26];
vector<pair<int, int> > vec;
int val[1000005], ans;
int main() {
  cin >> n >> s >> t;
  for (int i = 0; i < n; i++) pos[s[i] - 'a'].push_back(i);
  for (int i = 0; i < 26; i++) assert(pos[i].size() <= 1);
  for (int i = 0; i < t.size();) {
    int nxt = t.size();
    for (int j = i; j < t.size(); j++) {
      if (t[j] != t[i]) {
        nxt = j;
        break;
      }
    }
    int x = (upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), i) -
             pos[t[i] - 'a'].begin());
    x--;
    if (x == -1) {
      puts("-1");
      return 0;
    }
    for (int y = x; y < pos[t[i] - 'a'].size(); y++) {
      int g = pos[t[i] - 'a'][y];
      if (g >= nxt) break;
      int h;
      if (y == pos[t[i] - 'a'].size() - 1) {
        h = nxt - 1;
      } else {
        if (pos[t[i] - 'a'][y + 1] >= nxt - 1)
          h = nxt - 1;
        else
          h = pos[t[i] - 'a'][y + 1] - 1;
      }
      if (g < h) {
        val[g]++;
        val[h + 1]--;
      }
    }
    i = nxt;
  }
  for (int i = 1; i < n; i++) val[i] += val[i - 1];
  for (int i = 0; i < n; i++) ans = max(ans, val[i]);
  cout << ans << endl;
}
