#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, len, countt = 0, minn = 999999, cp = 0;
  cin >> n;
  char p[n];
  int c[256] = {0}, tm[256] = {0};
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    if (tm[p[i]] == 0) {
      tm[p[i]]++;
      cp++;
    }
  }
  int L = 0, R = 0;
  while (R < n) {
    c[p[R]]++;
    if (c[p[R]] == 1) {
      countt++;
    }
    while (countt == cp) {
      len = R - L + 1;
      if (len < minn) {
        minn = len;
      }
      c[p[L]]--;
      if (c[p[L]] == 0) {
        countt--;
      }
      L++;
    }
    if (countt < cp) {
      R++;
    }
  }
  cout << minn;
  return 0;
}
