#include <bits/stdc++.h>
using namespace std;
char a[101010];
int h[130], pre[130];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", a + 1);
  memset(h, 0, sizeof(0));
  memset(pre, 0, sizeof(pre));
  for (int i = 1; i <= n; i++) h[a[i]] = 1;
  int sum = 0;
  for (int i = 'a', j = 'A'; i <= 'z'; i++, j++) sum += h[i] + h[j];
  int mini = n, num = 0;
  int l = 1, r = 1;
  while (l <= r && r < n) {
    while (num <= sum && r <= n) {
      if (pre[a[r]] < l) num++;
      pre[a[r]] = r;
      if (num == sum) mini = min(mini, r - l + 1);
      if (num >= sum || r >= n) break;
      r++;
    }
    while (l <= r && num >= sum) {
      if (pre[a[l]] == l) {
        mini = min(mini, r - l + 1);
        num--, l++;
        break;
      }
      mini = min(mini, r - l + 1);
      l++;
    }
  }
  printf("%d\n", mini);
  return 0;
}
