#include <bits/stdc++.h>
const long long MAX = 1e5 + 1;
const long long MOD = 1e9 + 7;
void solve() {
  long long n, m, r, a, b, c, k, q, val, avg;
  long long ans = MAX;
  std::string s;
  std::cin >> n >> s;
  long long types = 0;
  std::map<char, bool> viewed{};
  for (char& p : s) {
    if (!viewed[p]) {
      viewed[p] = true;
      types++;
    }
  }
  long long start = 0;
  long long end = 0;
  long long diversity = 0;
  std::map<char, long long> count{};
  while (end < n) {
    count[s[end]]++;
    if (count[s[end]] == 1) diversity++;
    while (diversity == types && count[s[start]] > 1) {
      count[s[start]]--;
      start++;
    }
    if (diversity == types) ans = std::min(ans, end - start + 1);
    end++;
  }
  std::cout << ans << '\n';
}
signed main() {
  bool multi = false;
  if (multi) {
    long long t;
    std::cin >> t;
    for (long long i = 0; i < t; i++) solve();
  } else {
    solve();
  }
}
