#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int left, right;
  int ans = 1e9;
  string s;
  cin >> n;
  cin >> s;
  map<char, bool> num;
  map<char, int> flat;
  for (int i = 0; i < n; ++i) num[s[i]] = true;
  left = 0;
  for (right = 0; right < n; ++right) {
    flat[s[right]]++;
    while (flat.size() == num.size()) {
      flat[s[left]]--;
      if (flat[s[left]] == 0) flat.erase(s[left]);
      ans = min(ans, right - left + 1);
      left++;
    }
  }
  cout << ans << endl;
  return 0;
}
