#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
char str[N];
int cnt[200];
int main() {
  int n, index = 0, op = 0;
  scanf("%d", &n);
  scanf("%s", str + 1);
  char ch = '1';
  for (int i = 1; i <= n; ++i) {
    if (!cnt[str[i] - 'A']) {
      op++;
      cnt[str[i] - 'A'] = 1;
    }
  }
  memset(cnt, 0, sizeof(cnt));
  int res = N, cont = 0, l = 1, r = 1;
  for (int i = 1; i <= n; ++i) {
    if (!cnt[str[i] - 'A']) {
      cont++;
    }
    r = i;
    cnt[str[i] - 'A']++;
    if (cont >= op) {
      do {
        res = min(res, r - l + 1);
        cnt[str[l] - 'A']--;
        if (cnt[str[l] - 'A'] == 0) cont--;
        l++;
      } while (l <= r && cont >= op);
    }
  }
  if (cont >= op) {
    do {
      res = min(res, r - l + 1);
      cnt[str[l] - 'A']--;
      if (cnt[str[l] - 'A'] == 0) cont--;
      l++;
    } while (l <= r && cont >= op);
  }
  printf("%d\n", res);
  return 0;
}
