#include <bits/stdc++.h>
using namespace std;
int n;
char inp[100005];
set<char> k, s;
map<char, int> mp;
int st = 0;
int e = 0;
int ans = 10e9;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> inp[i];
    k.insert(inp[i]);
  }
  int sz = k.size();
  int letternum = 0;
  while (st <= e && e < n) {
    if (mp[inp[st]] > 1) {
      mp[inp[st]]--;
      st++;
    } else {
      mp[inp[e]]++;
      if (e < n && mp[inp[e]] == 1) {
        letternum++;
      }
      e++;
    }
    if (letternum == sz) ans = min(e - st, ans);
  }
  while (mp[inp[st]] > 1) {
    mp[inp[st]]--;
    st++;
    ans = min(e - st, ans);
  }
  cout << ans << endl;
  return 0;
}
