#include <bits/stdc++.h>
int main() {
  int n, i, count[1000], dis = 0, dis1 = 0, min = 100005, temp, l, r;
  char str[100005], a[100005], c;
  for (i = 0; i < 1000; i++) {
    count[i] = 0;
  }
  scanf("%d", &n);
  scanf("%c", &c);
  for (i = 0; i < n; i++) {
    scanf("%c", &str[i]);
    if (count[str[i] - 'A'] == 0) {
      dis++;
    }
    count[str[i] - 'A']++;
  }
  for (i = 0; i < 1000; i++) {
    count[i] = 0;
  }
  l = 1, r = 0, i = 0;
  while (i < n) {
    if (l > r) {
      a[++r] = str[i];
      count[str[i] - 'A']++;
      dis1++;
      i++;
      temp = r - l + 1;
      if (temp < min && dis1 >= dis) {
        min = temp;
      }
    } else {
      while (1) {
        if (count[a[l] - 'A'] > 1 && dis1 >= dis) {
          count[a[l] - 'A']--;
          l++;
        } else {
          break;
        }
      }
      temp = r - l + 1;
      if (temp < min && dis1 >= dis) {
        min = temp;
      }
      if (dis1 < dis) {
        a[++r] = str[i];
        if (count[str[i] - 'A'] == 0) {
          dis1++;
        }
        count[str[i] - 'A']++;
        i++;
      } else {
        a[++r] = str[i];
        count[str[i] - 'A']++;
        i++;
      }
      while (1) {
        if (count[a[l] - 'A'] > 1 && dis1 >= dis) {
          count[a[l] - 'A']--;
          l++;
        } else {
          break;
        }
      }
      temp = r - l + 1;
      if (temp < min && dis1 >= dis) {
        min = temp;
      }
    }
  }
  printf("%d\n", min);
}
