#include <bits/stdc++.h>
using namespace std;
int t, lp, rp, n, lo, hi, mid;
string s;
map<char, int> f;
bool can(int x) {
  for (auto p : s) f[p] = 0;
  t = 0;
  rp = 0;
  for (; rp < x; rp++) {
    if (f[s[rp]] == 0) t++;
    f[s[rp]]++;
  }
  if (t >= ((int)(f).size())) return 1;
  lp = 0;
  for (; rp < n; rp++, lp++) {
    if (f[s[lp]] == 1) t--;
    f[s[lp]]--;
    if (f[s[rp]] == 0) t++;
    f[s[rp]]++;
    if (t >= ((int)(f).size())) return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> s;
  lo = 1;
  hi = n;
  while (lo < hi) {
    mid = lo + ((hi - lo) >> 1);
    if (can(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << (lo) << endl;
  return 0;
}
