#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n;
string s;
set<char> flats;
int main() {
  cin >> n >> s;
  vector<int> arr(n, -1);
  for (int i = 0; i < n; i++) {
    flats.insert(s[i]);
  }
  for (auto &&c : flats) {
    int last = -1;
    for (int i = 0; i < n; i++) {
      if (s[i] == c) {
        last = i;
      }
      if (last == -1) {
        arr[i] = 100001;
      } else {
        arr[i] = max(arr[i], i - last + 1);
      }
    }
  }
  int current_min = 100001;
  int result;
  for (auto &&i : arr) {
    current_min = min(current_min, i);
  }
  cout << current_min << endl;
  return 0;
}
