#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int M = 60;
char s[N];
int a[N][M];
int fun(char c) {
  if (isupper(c)) return c - 'A' + 26;
  return c - 'a';
}
int judge(int l, int r) {
  int ans = 0;
  for (int i = 0; i < 54; i++)
    if (a[r][i] - a[l - 1][i] > 0) ans++;
  return ans;
}
int main() {
  int n;
  while (~scanf("%d%s", &n, s + 1)) {
    int num = 0;
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++) {
      int t = fun(s[i]);
      for (int j = 0; j < 54; j++) {
        a[i][j] = a[i - 1][j];
        if (j == t) {
          if (a[i][j] == 0) num++;
          a[i][j]++;
        }
      }
    }
    int ans = N;
    for (int i = 1; i <= n; i++) {
      int l = i, r = n;
      while (l < r) {
        int m = (l + r) >> 1;
        if (judge(i, m) >= num)
          r = m;
        else
          l = m + 1;
      }
      if (judge(i, l) == num) ans = min(ans, l - i + 1);
    }
    printf("%d\n", ans);
  }
  return 0;
}
