#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long T, n, m, k, x, y, z, l, r, d, ans, a[N], b[N], mod = 1e9 + 7;
string s;
void solve() {
  map<char, int> m, mm;
  string s;
  cin >> n >> s;
  ans = n;
  for (int i = 0; i < n; i++) m[s[i]]++;
  int k = m.size();
  for (long long i = 0; i <= n - 1; i++) {
    mm[s[i]] = i;
    int mn = n + 1;
    if (mm.size() == k) {
      for (auto i : mm) {
        mn = min(mn, i.second);
      }
      ans = min(ans, i - mn + 1);
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
