#include <bits/stdc++.h>
using namespace std;
long long n, l, r, kol, len;
map<char, long long> us, used;
string a;
map<long long, char> b;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    used[a[i]]++;
    if (used[a[i]] == 1) {
      len++;
    }
    b[i + 1] = a[i];
  }
  l = 1;
  r = n;
  while (r - l > 1) {
    long long mid = (r + l) / 2;
    for (int i = 1; i <= n; i++) {
      us[b[i]] = 0;
    }
    kol = 0;
    for (int i = 1; i <= n; i++) {
      us[b[i]]++;
      if (us[b[i]] == 1) {
        kol++;
      }
      if (i >= mid) {
        if (kol >= len) {
          r = mid;
          goto www;
        }
        if (us[b[i - mid + 1]] == 1) {
          kol--;
        }
        us[b[i - mid + 1]]--;
      }
    }
    l = mid;
  www:;
    for (int i = 1; i <= n; i++) {
      us[b[i]] = 0;
    }
    kol = 0;
  }
  for (int i = 1; i <= n; i++) {
    us[b[i]] = 0;
  }
  kol = 0;
  for (int i = 1; i <= n; i++) {
    us[b[i]]++;
    if (us[b[i]] == 1) {
      kol++;
    }
    if (i >= l) {
      if (kol >= len) {
        r = l;
        goto www1;
      }
      if (us[b[i - l + 1]] == 1) {
        kol--;
      }
      us[b[i - l + 1]]--;
    }
  }
www1:;
  cout << r;
  return 0;
}
