#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
char c[100010];
int m[100010];
int g[100010];
int main() {
  int n, i, k, l, r, mk, ans;
  scanf("%d", &n);
  gets(c);
  gets(c);
  mk = 0;
  for (i = 0; i < strlen(c); i++) {
    if (g[c[i]] == 0) {
      mk++;
      g[c[i]]++;
    }
  }
  k = 1;
  m[c[0]] = 1;
  r = 0;
  ans = n;
  for (l = 0; l < n - 1; l++) {
    while (r < n - 1 && k < mk) {
      r++;
      m[c[r]]++;
      if (m[c[r]] == 1) k++;
    }
    if (k == mk) ans = min(ans, r - l + 1);
    if (m[c[l]] == 1) k--;
    m[c[l]]--;
  }
  printf("%d", ans);
  return 0;
}
