#include <bits/stdc++.h>
using namespace std;
unordered_set<int> s;
string str;
int n;
int main() {
  cin >> n;
  long long ans = n;
  cin >> str;
  for (long long i = 0; i < n; i++) {
    s.insert(str[i]);
  }
  long long j = 0;
  map<char, int> m;
  long long cnt = 0;
  for (long long i = 0; i < n; i++) {
    while (j < n and cnt != s.size()) {
      if (m[str[j]] == 0) cnt++;
      m[str[j]]++;
      j++;
    }
    if (cnt != s.size()) {
      break;
    }
    ans = min(ans, j - i);
    m[str[i]]--;
    if (m[str[i]] == 0) cnt--;
  }
  cout << ans << endl;
  return 0;
}
