#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1e9 + 100;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 1e6 + 100;
int n;
char s[maxn], t[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  scanf("%s", s);
  scanf("%s", t);
  return true;
}

vector<int> pos[300];

void solve() {
  {
    bool ok = true;
    for (int i = 0; i < n; i++) {
      if (s[i] != t[i]) {
        ok = false;
      }
    }
    if (ok) {
      printf("0\n");
      return;
    }
  }
  for (int i = 0; i < 300; i++) {
    pos[i].clear();
  }
  for (int i = 0; i < n; i++) {
    pos[s[i]].pb(i);
  }
  vector<int> xs;
  vector<int> want;
  for (int i = n - 1; i >= 0; i--) {
    if (i == 0 || t[i] != t[i - 1]) {
      int mx = sz(xs) ? xs.back() : inf;
      mx = min(mx, i);
      int j = (int) (upper_bound(pos[t[i]].begin(), pos[t[i]].end(), mx) - pos[t[i]].begin());
      j--;
      if (j == -1) {
        printf("-1\n");
        return;
      }
      xs.pb(pos[t[i]][j]);
      want.pb(i);
    }
  }
  reverse(xs.begin(), xs.end());
  reverse(want.begin(), want.end());
  vector<int> magic;
  for (int i = 0; i < sz(xs); i++) {
    magic.pb(xs[i] - i);
  }
  magic.pb(want.back() - sz(xs) + 1);
  int ans = 1;
  for (int i = 0; i < sz(xs); i++) {
    int j = (int) (lower_bound(magic.begin(), magic.end(), want[i] - i) - magic.begin());
    ans = max(ans, 1 + j - i);
  }
  printf("%d\n", ans);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time: %.18f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}
#include <iostream>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

template<typename T>
class LazySegTree {
public:
    explicit LazySegTree(int n, T init, T def) : N(calcN_(n)), def(def) {
        mVal.assign(2*N+1, init);
        mLazy.assign(2*N+1, 0);
        mDirty.assign(2*N+1, 0);
    }
    void update(int l, int r, T value){
        updateImpl_(l, r, value, 0, 0, N);
    }
    void setVal(int idx, T value){
        T cur= get(idx, idx+1);
        update(idx, idx+1, value - cur);
    }
    T get(int l, int r){
        return getImpl_(l, r, 0, 0, N);
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void updateImpl_(int l, int r, T value, int idx, int rangeL, int rangeR){
        eval_(idx);
        if(r <= rangeL || rangeR <= l) return;
        if(l <= rangeL && rangeR <= r){
            setLazy_(idx, value);
            eval_(idx);
        } else {
            int rangeM = (rangeL+rangeR)/2;
            updateImpl_(l, r, value, 2*idx+1, rangeL, rangeM);
            updateImpl_(l, r, value, 2*idx+2, rangeM, rangeR);
            mVal[idx] = operate_(mVal[2*idx+1], mVal[2*idx+2]);
        }
    }
    void setLazy_(int idx, T value){
        mLazy[idx] += value;
        mDirty[idx] = 1;
    }
    T getImpl_(int l, int r, int idx, int rangeL, int rangeR){
        if(r <= rangeL || rangeR <= l) return def;
        eval_(idx);
        if(l <= rangeL && rangeR <= r) return mVal[idx];
        int rangeM = (rangeL+rangeR)/2;
        T a = getImpl_(l, r, 2*idx+1, rangeL, rangeM);
        T b = getImpl_(l, r, 2*idx+2, rangeM, rangeR);
        return operate_(a, b);
    }
    void eval_(int idx){
        if(!mDirty[idx]) return;
        mVal[idx] += mLazy[idx];
        if(idx < N-1){
            setLazy_(2*idx+1, mLazy[idx]);
            setLazy_(2*idx+2, mLazy[idx]);
        }
        mLazy[idx] = 0;
        mDirty[idx] = 0;
    }
    T operate_(T a, T b) const { return min(a, b); }
    const int N;
    const T def;
    vector<T> mVal;
    vector<T> mLazy;
    vector<int> mDirty;
};

int main(){
    int N, Q, A, B; cin >> N >> Q >> A >> B;
    vector<int> x(Q);
    for(auto& t : x) cin >> t;
    LazySegTree<long long> minus(N+1, 1LL << 40, INF);
    LazySegTree<long long> plus(N+1, 1LL << 40, INF);
    minus.setVal(A, abs(B-x[0]) - A);
    minus.setVal(B, abs(A-x[0]) - B);
    plus.setVal(A, abs(B-x[0]) + A);
    plus.setVal(B, abs(A-x[0]) + B);
    for(int i=1;i<Q;i++){
        auto v = min(minus.get(0, x[i]) + x[i], plus.get(x[i], N+1) - x[i]);
        minus.update(1, N+1, abs(x[i]-x[i-1]));
        plus.update(1, N+1, abs(x[i]-x[i-1]));
        minus.setVal(x[i-1], v - x[i-1]);
        plus.setVal(x[i-1], v + x[i-1]);
    }
    long long res = INF;
    for(int i=1;i<=N;i++) res = min(res, plus.get(i, i+1) - i);
    cout << res << endl;
}