#include <bits/stdc++.h>
using namespace std;
int f[55];
int cur[55];
int n;
char a[100005];
int main() {
  cin >> n;
  cin >> a;
  for (int i = 0; i < n; i++) {
    if (a[i] >= 'a' && a[i] <= 'z')
      f[a[i] - 'a']++;
    else
      f[a[i] - 'A' + 26]++;
  }
  int count = 0, temp = 0;
  for (int i = 0; i < 52; i++) {
    if (f[i]) count++;
  }
  int j = 0, val;
  int ans = 1e9;
  for (int i = 0; i < n; i++) {
    while (j < n && temp < count) {
      if (a[j] >= 'a' && a[j] <= 'z')
        val = a[j] - 'a';
      else
        val = a[j] - 'A' + 26;
      if (!cur[val]) temp++;
      cur[val]++;
      j++;
    }
    if (temp == count) ans = min(ans, j - i);
    if (a[i] >= 'a' && a[i] <= 'z')
      val = a[i] - 'a';
    else
      val = a[i] - 'A' + 26;
    if (--cur[val] == 0) temp--;
  }
  cout << ans;
  return 0;
}
