#include <bits/stdc++.h>
using namespace std;
map<char, int> ch, cn;
int main() {
  ios_base::sync_with_stdio(0);
  int i, j, x, n, cnt = 0, m = 10000000, y, k, g, flg, s, e;
  cin >> n;
  string in;
  cin >> in;
  for (i = 0; i <= n - 1; i++) {
    if (!ch[in[i]]) {
      ch[in[i]] = 1;
      cnt++;
    }
  }
  x = 0;
  s = e = 0;
  while (e < n) {
    if (cn[in[e]] == 0) x++;
    cn[in[e]]++;
    while (s < e) {
      if (cn[in[s]] > 1) {
        cn[in[s]]--;
        s++;
      } else
        break;
    }
    if (x == cnt) m = min(m, e - s + 1);
    e++;
  }
  cout << m;
}
