#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char in;
  int count[255];
  for (int i = 0; i < 255; i++) count[i] = 0;
  int min = 1000000000;
  int pre = 0;
  char str[n];
  for (int i = 0; i < n; i++) {
    cin >> in;
    str[i] = in;
    if (count[in] == 0) min = 1000000000;
    count[in]++;
    if (pre < i)
      for (int j = pre; j < i; j++) {
        if (count[str[j]] > 1) {
          count[str[j]]--;
          pre++;
        } else
          break;
      }
    if (min > i - pre + 1) min = i - pre + 1;
  }
  cout << min;
  return 0;
}
