#include <bits/stdc++.h>
using namespace std;
long long int sz, n;
string s;
map<char, long long int> M1, M2;
void check1() {
  long long int i, j;
  for (i = 0; i < sz; i++) {
    if (M1[s[i]] == 0) {
      n++;
    }
    M1[s[i]]++;
  }
}
long long int check2() {
  long long int l = 0, r = 0;
  long long int res = 999999;
  long long int k = 0;
  while (r < sz) {
    while (r < sz && k < n) {
      if (M2[s[r]] == 0) {
        k++;
      }
      M2[s[r]]++;
      r++;
    }
    while (l <= r) {
      if (k == n) res = min(res, (r - l));
      M2[s[l]]--;
      if (M2[s[l]] == 0) {
        k--;
        l++;
        break;
      }
      l++;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  long long int i, j, k, ans;
  cin >> sz;
  cin >> s;
  check1();
  ans = check2();
  cout << ans << "\n";
  return 0;
}
