#include <bits/stdc++.h>
using namespace std;
char str[200000 + 10];
int vis[1000];
int ch(char a) {
  if (a >= 'A' && a <= 'Z') {
    return a - 'A';
  }
  if (a >= 'a' && a <= 'z') {
    return a - 'a' + 26;
  }
}
int main(void) {
  int n, t;
  scanf("%d", &n);
  scanf("%s", str);
  int cnt = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++) {
    int p = ch(str[i]);
    if (!vis[p]) {
      vis[p] = 1;
      cnt++;
    }
  }
  int l, r, ans;
  l = r = 0;
  ans = n;
  memset(vis, 0, sizeof(vis));
  int ct = 1;
  vis[ch(str[0])] = 1;
  while (r < n) {
    if (ct == cnt) {
      ans = min(ans, r - l + 1);
      if (l == r) break;
      int p = ch(str[l]);
      l++;
      vis[p]--;
      if (!vis[p]) ct--;
    } else if (ct < cnt) {
      r++;
      if (r == n) break;
      int p = ch(str[r]);
      vis[p]++;
      if (vis[p] == 1) ct++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
