#include <bits/stdc++.h>
using namespace std;
map<char, int> M;
set<char> S;
char str[100005];
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    M.clear();
    S.clear();
    scanf("%s", str + 1);
    for (int i = 1; i <= n; i++) {
      S.insert(str[i]);
    }
    int sum = S.size();
    int s = 1, e = 0;
    int all = 0;
    int ans = n;
    while (++e <= n) {
      M[str[e]]++;
      if (M[str[e]] == 1) all++;
      if (all == sum) {
        while (M[str[s]] != 1) M[str[s++]]--;
        ans = min(ans, e - s + 1);
      }
    }
    printf("%d\n", ans);
  }
}
