#include <bits/stdc++.h>
using namespace std;
char s[100001];
bool hash1[1001];
int jl[1001], js = 0;
int n;
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  memset(hash1, 0, sizeof(hash1));
  memset(jl, 0, sizeof(jl));
  int head = 1, tail;
  for (int i = 1; i <= n; i++)
    if (!hash1[s[i]]) js++, hash1[s[i]] = 1;
  for (int i = 1; i <= n; i++) {
    jl[s[i]]++;
    if (jl[s[i]] == 1) js--;
    if (js == 0) {
      head = 1;
      tail = i;
      break;
    }
  }
  int ans = tail - head + 1;
  while (tail <= n) {
    jl[s[head]]--;
    if (jl[s[head++]] == 0) js++;
    if (js == 0) ans = min(ans, tail - head + 1);
    while (js != 0 && tail <= n) {
      jl[s[++tail]]++;
      if (jl[s[tail]] == 1) js--;
    }
    if (js == 0 && tail <= n) ans = min(ans, tail - head + 1);
  }
  printf("%d\n", ans);
  return 0;
}
