#include <bits/stdc++.h>
using namespace std;
int code(char c) {
  if ((c >= 'a') && (c <= 'z')) {
    return c - 'a';
  } else {
    return c - 'A' + ('z' - 'a' + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int i = 0, j = 0;
  bool p[100] = {false};
  for (int k = 0; k < s.size(); ++k) {
    int code = 0;
    if ((s[k] >= 'a') && (s[k] <= 'z')) {
      code = s[k] - 'a';
    } else {
      code = s[k] - 'A' + ('z' - 'a') + 1;
    }
    p[code] = true;
  }
  int codes = 0;
  for (int code = 0; code < 100; ++code) {
    if (p[code]) {
      ++codes;
    }
  }
  int current_count = 0;
  int pcurrent[100] = {0};
  int result = 1000000000;
  while ((i < s.size()) && (j < s.size())) {
    while ((j < s.size()) && (current_count < codes)) {
      ++j;
      if (!pcurrent[code(s[j - 1])]) {
        ++current_count;
      }
      ++pcurrent[code(s[j - 1])];
      if (current_count >= codes) {
        break;
      }
    }
    while ((i < j) && (current_count >= codes)) {
      ++i;
      --pcurrent[code(s[i - 1])];
      if (!pcurrent[code(s[i - 1])]) {
        --current_count;
        if (current_count < codes) {
          result = min(result, j - i + 1);
          break;
        }
      }
    }
  }
  cout << result << endl;
  return 0;
}
