#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  map<char, int> mp, mp2;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    mp2[s[i]]++;
  }
  int size2 = (int)(mp2.size());
  int l = 0, r = 0, count = 1000000006, m = 0, total = 0;
  int z = 0;
  while (l <= r) {
    if (total == size2) {
      count = min(count, r - l);
      mp[s[l]]--;
      if (!mp[s[l]]) total--;
      l++;
    } else if (r < n) {
      if (!mp[s[r]]) total++;
      mp[s[r]]++;
      r++;
    } else
      break;
  }
  cout << count << endl;
}
