#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
long long n;
string s;
long long have[N];
void solve() {
  cin >> n >> s;
  set<char> Pokemon;
  for (long long i = 0; i < (n); i++) Pokemon.insert(s[i]);
  long long cnt = ((long long)(Pokemon).size());
  long long cur = 0;
  long long lo = 0;
  long long ans = 1e9;
  for (long long hi = 0; hi < (n); hi++) {
    long long num = (long long)s[hi];
    if (!have[num]) cur++;
    have[num]++;
    while (lo < hi && have[(long long)s[lo]] > 1) {
      have[(long long)s[lo]]--;
      lo++;
    }
    if (cur == cnt) ans = min(ans, hi - lo + 1);
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
