#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int min = n;
  set<char> first;
  int num = 0;
  map<char, int> second;
  for (int t = 0; t < n; t++) {
    first.insert(char(s[t]));
  }
  int j = 0;
  for (set<char>::const_iterator it = first.begin(); it != first.end(); it++) {
    second[*it] = 0;
  }
  for (int i = 0; i < n; i++) {
    while ((j < n) and (first.size() > num)) {
      if (second[s[j]] == 0) {
        num++;
      }
      second[s[j]]++;
      if (j < n) {
        j++;
      }
    }
    if (first.size() == num) {
      if (j - i < min) {
        min = j - i;
      }
    } else
      break;
    second[s[i]]--;
    if (second[s[i]] == 0) {
      num--;
    }
  }
  cout << min;
  return 0;
}
