#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int l = 0;
  int r = 0;
  int res = 0;
  int d[305];
  for (int i = 0; i < 300; i++) d[i] = 0;
  d[s[l]]++;
  while (r < n) {
    while (d[s[l]] > 1) {
      d[s[l]]--;
      l++;
      res = min(res, r - l + 1);
    }
    r++;
    if (r == n) break;
    d[s[r]]++;
    if (d[s[r]] == 1) res = r - l + 1;
    while (d[s[l]] > 1) {
      d[s[l]]--;
      l++;
      res = min(res, r - l + 1);
    }
  }
  cout << max(res, 1);
  return 0;
}
