#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l = 0, r = 0, len = 1e9;
  string s;
  set<char> s1, s2;
  map<char, int> mp;
  cin >> n >> s;
  for (int i = 0; i < s.size(); i++) {
    s1.insert(s[i]);
  }
  while (l < n) {
    while (r < n && s2.size() != s1.size()) {
      s2.insert(s[r]);
      mp[s[r]]++;
      r++;
    }
    if (s2.size() == s1.size()) len = min(len, abs(l - r));
    if (mp[s[l]] < 2) s2.erase(s[l]);
    mp[s[l]]--;
    l++;
  }
  if (len != 1e9)
    cout << len << endl;
  else
    cout << 0 << endl;
  return 0;
}
