#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  string s;
  cin >> n >> s;
  set<int> l[26], u[26];
  for (int i = int(0); i <= int(n - 1); i++) {
    if (isupper(s[i])) {
      u[s[i] - 'A'].insert(i);
    } else {
      l[s[i] - 'a'].insert(i);
    }
  }
  int ans = n;
  for (int i = int(0); i <= int(n - 1); i++) {
    int x = i;
    bool ok = true;
    for (int j = int(0); j <= int(25); j++) {
      if (l[j].empty()) continue;
      if (l[j].lower_bound(i) == l[j].end()) {
        ok = false;
        break;
      }
      x = max(x, *l[j].lower_bound(i));
    }
    for (int j = int(0); j <= int(25); j++) {
      if (u[j].empty()) continue;
      if (u[j].lower_bound(i) == u[j].end()) {
        ok = false;
        break;
      }
      x = max(x, *u[j].lower_bound(i));
    }
    if (ok) ans = min(ans, x - i + 1);
  }
  cout << ans << '\n';
  return 0;
}
