#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 10;
bool cols[N];
bool rows[N];
unordered_set<char> types;
unordered_map<char, int> counting;
int main() {
  ios::sync_with_stdio(0);
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < ((int)s.size()); i++) types.insert(s[i]);
  int cnt = types.size();
  int end = -1;
  int curr = 0;
  int res = 1 << 30;
  for (int i = 0; i < ((int)s.size()); i++) {
    while (curr < cnt and ++end < (int)s.size())
      if (++counting[s[end]] == 1) curr++;
    if (curr == cnt) res = min(res, end - i + 1);
    if (--counting[s[i]] == 0) curr--;
  }
  printf("%d\n", res);
  return 0;
}
