#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  set<char> p;
  for (int i = 0; i < (int)(s).size(); i++) p.insert(s[i]);
  int start = (int)(p).size(), end = (int)(s).size();
  while (start < end) {
    int mid = start + (end - start) / 2;
    bool state = false;
    map<char, int> cnt;
    set<char> c;
    for (int i = 0; i < mid; i++) {
      cnt[s[i]]++;
      c.insert(s[i]);
    }
    if ((int)(c).size() == (int)(p).size())
      state = true;
    else {
      for (int i = mid; i < (int)(s).size(); i++) {
        cnt[s[i - mid]]--;
        cnt[s[i]]++;
        c.insert(s[i]);
        if (!cnt[s[i - mid]]) c.erase(s[i - mid]);
        if ((int)(c).size() == (int)(p).size()) {
          state = true;
          break;
        }
      }
    }
    if (state)
      end = mid;
    else
      start = mid + 1;
  }
  cout << start << endl;
  return 0;
}
