#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll gcd(int a,int b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(int a,int b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  int n;
  cin>>n;
  map<int,int> mp;
  rep(i,n){
    int a;
    cin>>a;
    mp[a]++;
  }
  if(mp.size()==n){
    cout<<"YES"<<endl;
    return 0;
  }
  cout<<"NO"<<endl;
}
#include <bits/stdc++.h>
#define N 1000020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
char s[N], t[N];
queue<int> q;

int main(int argc, char const *argv[]) {
  int n = read();
  scanf("%s", s + 1);
  scanf("%s", t + 1);

  if (!strcmp(s + 1, t + 1)) {
    return puts("0"), 0;
  }

  int ans = 0;

  for (int i = n, j = n; i; -- i) {
    if (t[i] == t[i - 1]) continue;
    j = min(j, i);
    while (j && s[j] != t[i]) {
      -- j;
    }
    if (!j) {
      return puts("-1"), 0;
    }

    while (!q.empty() && q.front() >= i + q.size()) {
      q.pop();
    }

    q.push(j);

    if (i != j) {
      ans = max(ans, (int) q.size());
    }
  }

  printf("%d\n", ans + 1);

  return 0;
}
/*
7
atcoder
aaaccce
*/