#include <bits/stdc++.h>
using namespace std;
string uppercase(string s) {
  transform(s.begin(), s.end(), s.begin(), ::toupper);
  return s;
}
string lowercase(string s) {
  transform(s.begin(), s.end(), s.begin(), ::tolower);
  return s;
}
void fast() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int main() {
  fast();
  int n;
  string s;
  cin >> n >> s;
  map<char, int> mp;
  for (int i = 0; i < s.size(); i++) {
    mp[s[i]]++;
  }
  int notDup = mp.size();
  mp.clear();
  int l = 0, r = 0;
  int ch = 0;
  int ans = INT_MAX;
  while (l <= r && r < n) {
    mp[s[r]]++;
    if (mp[s[r]] == 1) ch++;
    if (ch == notDup) {
      while (mp[s[l]] > 1) mp[s[l++]]--;
      ans = min(ans, r - l + 1);
    }
    r++;
  }
  cout << ans << '\n';
  return 0;
}
