#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char s[maxn];
bool is[128];
set<int> b[128];
int last[128];
int n;
int cnt = 0;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (is[s[i]] == false) {
      is[s[i]] = true;
      cnt++;
    }
  }
  if (cnt == 1) {
    cout << 1;
    return 0;
  }
  int c = 0, res = INT_MAX;
  fill(is, is + 128, false);
  for (int i = 0; i < n; i++) {
    if (c < cnt) {
      if (is[s[i]] == false) {
        b[s[i]].insert(i);
        is[s[i]] = true;
        c++;
      }
      last[s[i]] = i;
    }
    if (cnt == c) {
      set<char> l;
      int j;
      for (j = i; j >= 0; j--) {
        l.insert(s[j]);
        if (l.size() == cnt) break;
      }
      is[s[j]] = false;
      res = min(res, i - last[s[j]]);
      c--;
    }
  }
  cout << res + 1;
  return ~~(0 - 0);
}
