#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
map<char, int> mp;
int main() {
  int n, type = 0, ans;
  string s;
  cin >> n >> s;
  ans = n;
  int l = 0, r = 0;
  for (r = 0; r < n; r++) {
    mp[s[r]]++;
    while (mp[s[l]] > 1 && l < r) {
      mp[s[l]]--, l++;
    }
    if (mp.size() > type) type++, ans = r - l + 1;
    ans = min(ans, r - l + 1);
  }
  cout << ans;
  return 0;
}
