#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  string s;
  cin >> n;
  cin >> s;
  vector<long long> cnts(60, 0);
  long long k = 0;
  for (long long i = 0; i < n; i++) {
    if (cnts[s[i] - 65] == 0) k++;
    cnts[s[i] - 65]++;
  }
  for (long long i = 0; i < 60; i++) cnts[i] = 0;
  long long l = 0;
  long long r = -1;
  long long res = 100001;
  long long cnt = 0;
  while (r < n) {
    if (cnt < k) {
      r++;
      if (r == n) break;
      cnts[s[r] - 65]++;
      if (cnts[s[r] - 65] == 1) cnt++;
    } else if (cnt == k) {
      res = min(res, r - l + 1);
      cnts[s[l] - 65]--;
      if (cnts[s[l] - 65] == 0) cnt--;
      l++;
    }
  }
  cout << res;
  return 0;
}
