#include <bits/stdc++.h>
using namespace std;
char c[100005];
map<char, int> mp;
set<char> s;
int main() {
  int m;
  while (~scanf("%d", &m)) {
    scanf("%s", c);
    mp.clear();
    s.clear();
    for (int i = 0; i < m; i++) {
      s.insert(c[i]);
    }
    int k = s.size(), l = 0, r = 0, cot = 0, ans = m;
    while (true) {
      while (r < m && cot < k) {
        if (mp[c[r++]]++ == 0) cot++;
      }
      if (cot < k) break;
      ans = min(ans, r - l);
      if (--mp[c[l++]] == 0) cot--;
    }
    printf("%d\n", ans);
  }
  return 0;
}
