#include <bits/stdc++.h>
int mark[200];
char type[100010];
int main() {
  int i, j, n, num = 0, min = 2100000000;
  scanf("%d", &n);
  scanf(" %s", type);
  for (i = 0; i < n; i++) {
    if (mark[type[i]] == 0) {
      mark[type[i]] = 1;
      num++;
    }
  }
  for (i = 0; i < 150; i++) {
    mark[i] = 0;
  }
  i = j = 0;
  while (num) {
    if (mark[type[j]] == 0) num--;
    mark[type[j++]]++;
  }
  j--;
  mark[type[j]]--;
  while (j < n) {
    mark[type[j]]++;
    while (mark[type[i]] > 1) {
      mark[type[i++]]--;
    }
    if (j - i + 1 < min) min = j - i + 1;
    j++;
  }
  printf("%d\n", min);
  return 0;
}
