#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const int MOD = 1000000007;
const long long L_MAX = 9223372036854775807;
const int I_MAX = 2147483647;
char s[10000010], t[100];
bool findMinWindow(int &minl, int &minr) {
  int m = strlen(s);
  int n = strlen(t);
  int count1[256], count2[256];
  for (int i = 0; i < 256; i++) {
    count1[i] = 0;
    count2[i] = 0;
  }
  for (int i = 0; i < n; i++) count2[t[i]]++;
  int matched = 0;
  int minL = m + 1, st = 0;
  for (int i = 0; i < m; i++) {
    if (count2[s[i]] == 0) continue;
    count1[s[i]]++;
    if (count1[s[i]] <= count2[s[i]]) matched++;
    if (matched == n) {
      while (count2[s[st]] == 0 || count1[s[st]] > count2[s[st]]) {
        if (count1[s[st]] > count2[s[st]]) count1[s[st]]--;
        st++;
      }
      if (i - st + 1 < minL) {
        minL = i - st + 1;
        minl = st;
        minr = i;
      }
    }
  }
  return (matched == n);
}
int main(int argc, const char **argv) {
  int N, l, r;
  set<char> S1;
  while (cin >> N) {
    cin >> s;
    S1.clear();
    for (int i = 0; i <= (N - 1); ++i) S1.insert(s[i]);
    int l = 0;
    for (auto a : S1) t[l++] = a;
    t[l] = '\0';
    if (findMinWindow(l, r)) {
      cout << (r - l + 1) << endl;
    }
  }
  return 0;
}
