#include <bits/stdc++.h>
using namespace std;
long long n;
string s;
long long totPok;
bool isPossible(long long mi) {
  map<char, long long> mp;
  for (long long i = 1; i <= mi; i++) mp[s[i]]++;
  if (mp.size() == totPok) return true;
  for (long long i = mi + 1; i <= n; i++) {
    mp[s[i]]++;
    mp[s[i - mi]]--;
    if (mp[s[i - mi]] == 0) mp.erase(s[i - mi]);
    if (mp.size() == totPok) return true;
  }
  return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  cin >> s;
  s = '?' + s;
  map<char, long long> mp;
  for (long long i = 1; i <= n; i++) mp[s[i]]++;
  totPok = mp.size();
  long long st = totPok, en = n;
  long long ans;
  while (st <= en) {
    long long mi = (st + en) / 2;
    if (isPossible(mi)) {
      ans = mi;
      en = mi - 1;
    } else {
      st = mi + 1;
    }
  }
  cout << ans;
  return 0;
}
