#include <bits/stdc++.h>
std::set<char> s;
int ch[200];
using namespace std;
int main() {
  int n;
  string x;
  cin >> n;
  cin >> x;
  for (int i = 0; i < n; i++) {
    s.insert(x[i]);
  }
  int lo = s.size();
  int hi = n;
  while (lo < hi) {
    int mid = lo + (hi - lo) / 2;
    int distinct_count = 0;
    int slow = 0;
    int i = 0;
    for (i = 0; i < n; i++) {
      if (i < mid) {
        if (ch[x[i] - 'A'] == 0) distinct_count++;
        ch[x[i] - 'A']++;
      } else {
        ch[x[slow] - 'A']--;
        if (ch[x[slow] - 'A'] == 0) distinct_count--;
        slow++;
        if (ch[x[i] - 'A'] == 0) distinct_count++;
        ch[x[i] - 'A']++;
      }
      if (distinct_count == s.size()) {
        break;
      }
    }
    for (int j = 0; j < n; j++) ch[x[j] - 'A'] = 0;
    if (distinct_count == s.size())
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo << endl;
}
