#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  unordered_map<char, int> cnt;
  int unique = 0;
  for (char c : s) {
    if (cnt[c] == 0) unique++;
    cnt[c]++;
  }
  cnt.clear();
  int now = 0;
  int idx = 0;
  for (; idx < s.length(); idx++) {
    char c = s[idx];
    if (now == unique) break;
    if (cnt[c] == 0) now++;
    cnt[c]++;
  }
  int ans = idx;
  for (int i = 1; i < s.length(); i++) {
    cnt[s[i - 1]]--;
    if (cnt[s[i - 1]] == 0) {
      now--;
    }
    while (now < unique && idx < s.length()) {
      char c = s[idx++];
      if (cnt[c] == 0) now++;
      cnt[c]++;
    }
    if (now == unique) ans = min(ans, idx - i);
  }
  cout << ans << endl;
  return 0;
}
