#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mod1 = 998244353;
const long long inf = 92233720000000000ll;
long long n, l, r, ans;
map<long long, long long> mp;
string s;
void solve() {
  cin >> n >> s;
  for (long long i = (0); i < (n); i++) mp[s[i]]++;
  long long tot = mp.size();
  l = 0, r = 0;
  mp.clear();
  while (r < n && mp.size() < tot) {
    mp[s[r]]++;
    r++;
  }
  ans = r - l;
  for (long long i = (l); i < (n); i++) {
    mp[s[i]]--;
    if (mp[s[i]] == 0) mp.erase(s[i]);
    while (r < n && mp.size() < tot) {
      mp[s[r]]++;
      r++;
    }
    if (mp.size() == tot) ans = min(ans, r - i - 1);
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
