#include <bits/stdc++.h>
using namespace std;
ifstream in("in.txt");
ofstream out("");
string second;
int first[125], n, nm = 0;
int trashforces(int x) {
  int nr = 0, i, m = 0, j;
  for (i = 0; i <= 26; ++i) first['A' + i] = first['a' + i] = 0;
  for (i = 0; i < n; ++i) {
    if (i >= x) {
      --first[second[i - x]];
      if (!first[second[i - x]]) --nr;
    }
    ++first[second[i]];
    if (first[second[i]] == 1) ++nr;
    m = max(m, nr);
  }
  return m;
}
int main() {
  int i, pas = 1 << 29, r = 0;
  cin >> n >> second;
  for (i = 0; i < n; ++i) {
    if (!first[second[i]]) ++nm;
    first[second[i]] = 1;
  }
  while (pas) {
    if (r + pas <= n && trashforces(r + pas) < nm) r += pas;
    pas /= 2;
  }
  cout << r + 1;
  return 0;
}
