#include <bits/stdc++.h>
using namespace std;
int n, ans = 1e5, freq[125];
bool exst[125];
string s;
int main() {
  scanf("%d", &n);
  cin >> s;
  for (int i = 0; i < n; i++) {
    exst[s[i]] = true;
  }
  freq[s[0]] = 1;
  for (int i = 0, j = 0; j < n;) {
    bool valid = 1;
    for (int k = 0; k <= 'z'; k++) {
      if (exst[k] && !freq[k]) {
        j++;
        freq[s[j]]++;
        valid = 0;
        break;
      }
    }
    if (valid) {
      ans = min(ans, j - i + 1);
      freq[s[i]]--;
      i++;
    }
  }
  printf("%d", ans);
}
