#include <bits/stdc++.h>
using namespace std;
char a[100001];
int main() {
  int N;
  scanf("%d", &N);
  scanf("%s", a);
  set<char> ck;
  for (int i = 0; a[i]; i++) ck.insert(a[i]);
  int n = ck.size();
  int l = 0, r = 0;
  int b[128] = {};
  int ans = N;
  for (int i = 0; i < N; i++) {
    if (b[a[i]] == 0) n--;
    b[a[i]]++;
    r++;
    while (n == 0) {
      if (b[a[l]] == 1) break;
      b[a[l]]--;
      l++;
    }
    if (n == 0) ans = min(ans, r - l);
  }
  printf("%d", ans);
  return 0;
}
