#include <bits/stdc++.h>
using namespace std;
string s;
int k, n;
set<char> st;
void CHECK() {
  for (int i = 0; i < s.length(); i++) st.insert(s[i]);
}
bool Check(int End) {
  k = 0;
  map<char, int> mp;
  for (int i = 0; i < End; i++) {
    if (mp[s[i]] == 0) k++;
    mp[s[i]]++;
  }
  if (k == st.size()) return true;
  int Befor = 0, After = End - 1;
  while (After < n - 1) {
    Befor++;
    After++;
    mp[s[Befor - 1]]--;
    if (mp[s[Befor - 1]] == 0) k--;
    mp[s[After]]++;
    if (mp[s[After]] == 1) k++;
    if (k == st.size()) return true;
  }
  return false;
}
int res = -1;
int Binary_Search(int Start, int End) {
  while (Start <= End) {
    int Mid = (Start + End) / 2;
    if (Check(Mid)) {
      res = Mid;
      End = Mid - 1;
    } else {
      Start = Mid + 1;
    }
  }
  return res;
}
int main() {
  while (1) {
    cin >> n >> s;
    CHECK();
    cout << Binary_Search(st.size(), n + 1);
    return 0;
  }
}
