#include <bits/stdc++.h>
using namespace std;
int n, s[100010][200], ans = 0x3f3f3f3f, vis[200], sub, cunt;
char a[100010];
bool check(int l, int r) {
  int cnt = 0;
  for (int i = 65; i <= 122; i++)
    if (s[r][i] - s[l - 1][i]) cnt++;
  return (cnt == cunt);
}
int find(int pos) {
  int l = pos, r = n;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(pos, mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (check(pos, r))
    return r;
  else
    return 0x3f3f3f3f;
}
int main() {
  scanf("%d%s", &n, a + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 65; j <= 122; j++) s[i][j] = s[i - 1][j];
    s[i][a[i]]++;
    if (!vis[a[i]]) cunt++, vis[a[i]] = 1;
  }
  for (int i = 1; i <= n; i++) {
    ans = min(ans, find(i) - i + 1);
    if (--vis[a[i]] == 0) sub++;
  }
  printf("%d\n", ans);
  return 0;
}
