#include <bits/stdc++.h>
using namespace std;
long long n, c, mn = 1e10;
string s;
set<char> st;
map<char, long long> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> s;
  for (long long i = 0; i < s.size(); i++) st.insert(s[i]);
  long long second = st.size();
  long long i = -1, j = -1;
  while (true) {
    if (c < second) {
      j++;
      if (j == n) break;
      if (!mp[s[j]]) c++;
      mp[s[j]]++;
    } else {
      mn = min(mn, j - i);
      i++;
      if (i == n) break;
      mp[s[i]]--;
      if (!mp[s[i]]) c--;
    }
  }
  cout << mn << endl;
}
