#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k, m, n;
  cin >> n;
  string str;
  cin >> str;
  map<char, int> ma;
  for (i = 0; i < n; i++) {
    ma[str[i]] = 1;
  }
  string pat = "";
  for (auto i : ma) {
    pat.push_back(i.first);
  }
  int st[256] = {0};
  int pa[256] = {0};
  for (i = 0; i < pat.size(); i++) {
    pa[pat[i]]++;
  }
  int l = 0, r = 0;
  int cnt = 0;
  int ans = INT_MAX;
  for (r = 0; r < n; r++) {
    st[str[r]]++;
    if (st[str[r]] == pa[str[r]]) {
      cnt++;
    }
    if (cnt == pat.size()) {
      while (st[str[l]] == 0 || st[str[l]] > pa[str[l]]) {
        st[str[l]]--;
        l++;
      }
      ans = min(ans, r - l + 1);
    }
  }
  cout << ans;
}
