#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
typedef long long ll;
void my_return(ll code) { exit(code); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll my_exp(ll a, ll b, ll MOD = numeric_limits<ll>::max()) {
  a %= MOD;
  if (b == 0) {
    return 1;
  } else {
    return ((b % 2 == 1 ? a : 1) * my_exp(a * a, b / 2, MOD)) % MOD;
  }
}
bool is_prime(ll n) {
  if (n != 2 && n % 2 == 0) {
    return false;
  } else {
    for (int i = 3; (i * i) <= n; i += 2) {
      if (n % i == 0) return false;
    }
    return true;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  string s;
  cin >> s;
  set<char> ntype;
  for (decltype(s.begin()) it = s.begin(); it != s.end(); it++)
    ntype.insert(*it);
  ll i = 0, j = 0;
  map<char, ll> count;
  ll ans = n;
  while (j < n) {
    while (j < n && count.size() < ntype.size()) {
      count[s[j]]++;
      ++j;
    }
    while (i <= j && count.size() >= ntype.size()) {
      ans = min(ans, j - i);
      count[s[i]]--;
      if (count[s[i]] == ll(0)) {
        count.erase(s[i]);
      }
      ++i;
    }
  }
  cout << ans;
  my_return(0);
}
