#include <bits/stdc++.h>
char s[100001];
int c[256];
int main(void) {
  int n, l = 0, r, v;
  scanf("%d %s", &n, s);
  for (char *p = s; *p; p++) c[*p]++;
  for (r = n - 1; c[s[r]] > 1; r--) c[s[r]]--;
  for (v = r + 1, c[s[r]]--; r < n; r++) {
    for (c[s[r]]++; c[s[l]] > 1; l++) c[s[l]]--;
    if (r - l + 1 < v) v = r - l + 1;
  }
  printf("%d\n", v);
}
