#include <bits/stdc++.h>
using namespace std;
int A[100009], m[200];
string s;
int mark[60];
int main() {
  int n, l, mm = 1, ans = 1000000, h, t;
  cin >> n >> s;
  l = s.length();
  for (long long int i = (long long int)0; i <= (long long int)l - 1; i++) {
    if (m[(int)s[i]])
      A[i + 1] = m[(int)s[i]];
    else {
      A[i + 1] = m[(int)s[i]] = mm++;
    }
  }
  mm--;
  if (mm == 1) {
    cout << 1;
    return 0;
  }
  int marked = 0, ind = 1, ch;
  while (marked < mm) {
    if (!mark[A[ind]]) marked++;
    mark[A[ind]]++;
    ind++;
  }
  ind--;
  t = ind;
  h = 1;
  while (t <= l) {
    ans = min(ans, t - h + 1);
    if (mark[A[h]] > 1) {
      mark[A[h]]--;
      h++;
      continue;
    }
    mark[A[h]] = 0;
    ch = A[h];
    h++;
    t++;
    while (A[t] != ch) {
      if (t == l + 1) break;
      mark[A[t]]++;
      t++;
    }
    if (t == l + 1) break;
    mark[ch] = 1;
  }
  cout << ans << "\n";
  return 0;
}
