#include <bits/stdc++.h>
using namespace std;
int L[205];
int T[100005][205];
vector<int> V;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) V.push_back(s[i]);
  sort(V.begin(), V.end());
  V.resize(distance(V.begin(), unique(V.begin(), V.end())));
  for (int i = 0; i <= 200; i++) L[i] = 1000000000;
  for (int i = n - 1; i >= 0; i--) {
    L[s[i]] = i;
    for (int j = 0; j < 200; j++) T[i][j] = L[j];
  }
  int ans = 1000000000;
  for (int i = 0; i < n; i++) {
    int mx = 0;
    for (int j = 0; j < V.size(); j++) mx = max(mx, T[i][V[j]] - i + 1);
    ans = min(ans, mx);
  }
  cout << ans << "\n";
  return 0;
}
