#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, S = 0;
char x[2], s[MAXN];
int viv[MAXN];
bool use[MAXN];
int cqf() {
  int l = -1, r = -1;
  int ans = MAXN, sum = 0;
  while (true) {
    while (r <= n && sum < S) {
      r++;
      if (!viv[s[r]] && use[s[r]]) sum++;
      viv[s[r]]++;
    }
    if (sum < S) break;
    ans = min(ans, r - l + 1);
    if (viv[s[l]] == 1 && use[s[l]]) sum--;
    viv[s[l]]--;
    l++;
  }
  return ans;
}
int main() {
  memset(viv, 0, sizeof(viv));
  memset(use, 0, sizeof(use));
  scanf("%d", &n);
  gets(x);
  gets(s);
  for (int i = 0; i < n; i++) {
    if (use[s[i]] == false) S++;
    use[s[i]] = true;
  }
  printf("%d\n", cqf());
  return 0;
}
