#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <class nmsl>
inline void read(nmsl &x) {
  x = 0;
  char ch = getchar(), w = 0;
  while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = w ? -x : x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  string s;
  cin >> s;
  int p = 0;
  int ans = n;
  int r, l = 0;
  map<char, int> m;
  for (r = 0; r < n; r++) {
    m[s[r]]++;
    while (m[s[l]] > 1 && l < r) {
      m[s[l]]--;
      l++;
    }
    if (m.size() > p) {
      p++;
      ans = r - l + 1;
    }
    ans = min(ans, r - l + 1);
  }
  cout << ans << "\n";
  return 0;
}
