#include <bits/stdc++.h>
using namespace std;
char arr[100010];
set<char> ss;
map<char, int> mm;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf(" %c", arr + i);
    ss.insert(arr[i]);
  }
  int size = ss.size();
  int ans = n, l = 1, r = 0, cnt = 0;
  while (l <= n && r < n) {
    r++;
    if (mm[arr[r]] == 0) cnt++;
    mm[arr[r]]++;
    while (cnt == size) {
      ans = min(ans, r - l + 1);
      mm[arr[l]]--;
      if (mm[arr[l]] == 0) cnt--;
      l++;
    }
    if (l > r) break;
  }
  printf("%d\n", ans);
  return 0;
}
