#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  set<char> all;
  for (auto c : s) all.insert(c);
  const long long sz = all.size();
  if (sz == 1) {
    cout << "1\n";
    return 0;
  }
  long long lo = 1;
  long long hi = n;
  long long a = n;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    map<char, long long> freq;
    bool poss = false;
    long long dist = 0;
    for (long long i = 0; i < mid; i++) {
      freq[s[i]]++;
      if (freq[s[i]] == 1) dist++;
    }
    for (long long i = mid; i < n; i++) {
      if (dist == sz) poss = true;
      if (--freq[s[i - mid]] == 0) dist--;
      if (++freq[s[i]] == 1) dist++;
      if (dist == sz) poss = true;
    }
    if (poss) {
      a = min(a, mid);
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << a << '\n';
  return 0;
}
