#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_set<char> types;
  vector<char> flats(n);
  for (char& p : flats) {
    cin >> p;
    types.insert(p);
  }
  int mini = INT32_MAX;
  unordered_map<char, int> pokemon;
  int left = 0;
  for (int i = 0; i < n; i++) {
    pokemon[flats[i]]++;
    while (left + 1 <= i && pokemon.count(flats[left]) &&
           pokemon[flats[left]] > 1) {
      pokemon[flats[left]]--;
      left++;
    }
    if (pokemon.size() == types.size()) {
      mini = min(mini, i - left + 1);
    }
  }
  cout << mini;
}
