#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000 * 1000;
const long long inf64 = 1ll * inf * inf;
bool solve() {
  vector<int> u(300);
  int n;
  scanf("%d", &n);
  char s[100100];
  scanf("%s", &s);
  int res = inf;
  for (int i = 0; i < n; i++) {
    u[s[i]] = 1;
  }
  int all = count((u).begin(), (u).end(), 1);
  u.assign(300, 0);
  for (int cur = 0, j = 0, i = 0; i < n; i++) {
    if (!u[s[i]])
      u[s[i]] = 1, cur++;
    else
      u[s[i]]++;
    while (j < i && u[s[j]] > 1) u[s[j++]]--;
    if (cur == all) res = min(res, i - j + 1);
  }
  printf("%d\n", res);
  return true;
}
int main() {
  solve();
  return 0;
}
