#include <bits/stdc++.h>
using namespace std;
char z[100100];
map<char, bool> av;
map<char, int> con;
vector<char> poke;
int us[52];
bool comp() {
  for (int i = 0; i < poke.size(); i++)
    if (!us[i]) return false;
  return true;
}
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", z);
  string s = string(z);
  int c = 0;
  for (int i = 0; i < s.size(); i++) {
    if (av[s[i]]) continue;
    av[s[i]] = true;
    con[s[i]] = c++;
    poke.push_back(s[i]);
  }
  int l = 0, r = 0;
  int ans = n;
  while (l < n && r < n) {
    us[con[s[r]]]++;
    if (comp()) {
      ans = min(ans, r - l + 1);
      while (true) {
        ans = min(ans, r - l + 1);
        if (l == r) {
          cout << "1\n";
          return 0;
        }
        us[con[s[l]]]--;
        l++;
        if (us[con[s[l - 1]]] == 0) break;
      }
    }
    r++;
  }
  cout << ans << '\n';
  return 0;
}
