#include <bits/stdc++.h>
char t[100010];
int mark[52];
int ord(char c) {
  if (c >= 'A' && c <= 'Z')
    return c - 'A';
  else
    return c - 'a' + 26;
}
int main() {
  int i, l, r, cur, tot, n, ans;
  for (i = 0; i < 52; i++) mark[i] = 0;
  scanf("%d%s", &n, t);
  for (i = 0; i < n; i++) mark[ord(t[i])] = 1;
  for (tot = 0, i = 0; i < 52; i++) tot += mark[i], mark[i] = 0;
  ans = n;
  for (l = 0, r = 0; r < n;) {
    cur = ord(t[r]);
    r++;
    mark[cur]++;
    if (mark[cur] == 1)
      tot--;
    else
      for (; mark[ord(t[l])] > 1; mark[ord(t[l])]--, l++)
        ;
    if (tot == 0 && r - l < ans) ans = r - l;
  }
  printf("%d\n", ans);
  return 0;
}
