#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int cnt[70];
bool f[70];
char a[MAXN];
int main() {
  int n, ans = MAXN;
  char c;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (islower(a[i]))
      f[a[i] - 'a'] = true;
    else
      f[a[i] - 'A' + 26] = true;
  }
  int l = 1;
  for (int i = 1; i <= n; i++) {
    if (islower(a[i]))
      cnt[a[i] - 'a']++;
    else
      cnt[a[i] - 'A' + 26]++;
    int temp = (islower(a[l]) ? a[l] - 'a' : a[l] - 'A' + 26);
    while (cnt[temp] > 1) {
      l++;
      cnt[temp]--;
      temp = (islower(a[l]) ? a[l] - 'a' : a[l] - 'A' + 26);
    }
    bool gg = false;
    for (int j = 0; j <= 51; j++)
      if (f[j] && cnt[j] == 0) {
        gg = true;
        break;
      }
    if (!gg) ans = min(ans, i - l + 1);
  }
  cout << ans;
  return 0;
}
