#include <bits/stdc++.h>
using namespace std;
set<char> pokemon;
int vis[1000];
string s;
int n;
bool ok(int mid) {
  memset(vis, 0, sizeof(vis));
  int sum = 0;
  for (int i = 0; i < mid; i++) {
    if (vis[s[i]] == 0) sum++;
    vis[s[i]]++;
  }
  if (sum == pokemon.size()) return true;
  for (int i = 0; i < n - mid; i++) {
    vis[s[i]]--;
    if (vis[s[i]] == 0) sum--;
    if (vis[s[i + mid]] == 0) sum++;
    vis[s[i + mid]]++;
    if (sum == pokemon.size()) return true;
  }
  return false;
}
int main() {
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; i++) {
    pokemon.insert(s[i]);
  }
  int l = pokemon.size();
  int r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    if (ok(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
