#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  set<char> st;
  for (auto i : s) st.insert(i);
  map<char, long long int> have;
  long long int ans = 1e18;
  long long int l = 0, r = 0;
  long long int cur = 0;
  while (r < n) {
    have[s[r]]++;
    if (have[s[r]] == 1) cur++;
    while (have[s[l]] > 1) {
      have[s[l]]--;
      l++;
    }
    if (cur == st.size()) ans = min(ans, r - l + 1);
    r++;
  }
  cout << ans << "\n";
}
