#include <bits/stdc++.h>
using namespace std;
char a[100505];
int vis[100];
char ch[100];
int p;
int judge(int y) {
  int i;
  if (y == -1) return 1;
  for (i = 0; i <= p; i++) {
    if (vis[i] == 0) {
      return 1;
    }
  }
  return 0;
}
int main() {
  int n, m;
  int sum = 0;
  scanf("%d", &n);
  scanf("%s", a);
  int flag = 0;
  p = -1;
  int i, j = -1, k;
  for (i = 0; i < n; i++) {
    flag = 0;
    for (j = 0; j <= p; j++) {
      if (a[i] == ch[j]) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      p++;
      ch[p] = a[i];
    }
  }
  j = -1;
  int ans = 999999999;
  int p1 = n, p2 = n;
  for (i = 0; i < n; i++) {
    while (judge(j)) {
      if (j == n - 1)
        break;
      else {
        j++;
        for (k = 0; k < p; k++) {
          if (ch[k] == a[j]) break;
        }
        vis[k]++;
      }
    }
    if (judge(j) == 0) ans = min(ans, j - i + 1);
    for (k = 0; k <= p; k++) {
      if (ch[k] == a[i]) break;
    }
    vis[k]--;
  }
  printf("%d\n", ans);
}
