#include <bits/stdc++.h>
using namespace std;
ifstream fin("Sisend.txt");
int n, jad[300];
string s;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cin >> n >> s;
  for (int(i) = (0); ((i)) < ((s.size())); ((i))++) {
    int k = (int)s[i];
    jad[k] = 1;
  }
  int a = 0;
  for (int(i) = (0); ((i)) < ((300)); ((i))++) a += jad[i], jad[i] = 0;
  int su = 0, in = 0, vas = 100000;
  for (int(i) = (0); ((i)) < ((s.size())); ((i))++) {
    while (in < n and su < a) {
      int k = (int)s[in];
      in++;
      if (!jad[k]) su++;
      jad[k]++;
    }
    if (su == a) vas = min(vas, in - i);
    int k = (int)s[i];
    jad[k]--;
    if (!jad[k]) su--;
  }
  cout << vas;
}
