#include <bits/stdc++.h>
using namespace std;
map<char, queue<int> > c;
string x;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  cin >> x;
  for (int i = 0; i < n; i++) {
    c[x[i]].push(i);
  }
  int ans = 1e9;
  while (true) {
    map<char, queue<int> >::iterator it = c.begin();
    char t;
    int mi = 1e9, ma = 0;
    while (it != c.end()) {
      if (it->second.size() == 0) {
        cout << ans;
        return 0;
      }
      ma = max(ma, it->second.front());
      if (it->second.front() < mi) {
        t = it->first;
        mi = it->second.front();
      }
      it++;
    }
    ans = min(ans, (ma - mi + 1));
    c[t].pop();
  }
  return 0;
}
