#include <bits/stdc++.h>
using namespace std;
int cnt[256];
int main() {
  string s;
  int n, i, l, r, ans = 1e9, j, c = 0, curr;
  cin >> n;
  cin >> s;
  for (i = 0; i < s.size(); i++) {
    c += !cnt[s[i]];
    cnt[s[i]]++;
  }
  fill(cnt, cnt + 256, 0);
  curr = 0;
  for (i = 0, j = 0; i < n; i++) {
    curr += !cnt[s[i]];
    cnt[s[i]]++;
    while (j <= i and cnt[s[j]] > 1) {
      cnt[s[j]]--;
      j++;
    }
    if (c == curr) {
      ans = min(ans, i - j + 1);
    }
  }
  cout << ans << endl;
  return 0;
}
