#include <bits/stdc++.h>
using namespace std;
const long long base = 31;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 7;
long long hx[4] = {1, 0, -1, 0};
long long hy[4] = {0, 1, 0, -1};
long long n, ans;
string s;
map<char, long long> m;
bool check(long long x) {
  map<char, long long> demo;
  for (long long i = 0; i < x; i++) demo[s[i]]++;
  if (demo.size() == m.size()) return 1;
  long long dem = demo.size();
  for (long long i = x; i < n; i++) {
    if (demo[s[i]] == 0) dem++;
    demo[s[i]]++;
    if (demo[s[i - x]] == 1) dem--;
    demo[s[i - x]]--;
    if (dem == m.size()) return 1;
  }
  return 0;
}
void binary(long long l, long long r) {
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid) == 1) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
}
void program() {
  cin >> n >> s;
  for (char i : s) m[i]++;
  ans = n;
  binary(0, n);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  program();
}
