#include <bits/stdc++.h>
using namespace std;
string str;
map<char, int> M;
int main() {
  int n;
  cin >> n;
  cin >> str;
  for (int i = 0; i < n; i++) {
    M[str[i]] = 1;
  }
  int num = M.size();
  M.clear();
  int cnt = 1;
  int l = 0, r = 0;
  M[str[0]] = 1;
  int ans = 1e9;
  while (1) {
    if (r >= n) break;
    while (cnt < num) {
      r++;
      if (r >= n) break;
      if (!M[str[r]]) {
        cnt++;
      }
      M[str[r]]++;
    }
    while (cnt >= num) {
      ans = min(ans, r - l + 1);
      M[str[l]]--;
      if (!M[str[l]]) {
        cnt--;
      }
      l++;
    }
  }
  printf("%d", ans);
}
