#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(52, 0);
  pair<int, int> mx, mn;
  for (int i = 1; i <= n; ++i) {
    char c;
    cin >> c;
    int num = c < 'a' ? c - 'A' : c - 'a' + 26;
    if (!a[num]) {
      mx = make_pair(i, num);
      if (!mn.first) mn = mx;
    }
    a[num] = i;
    if (num == mn.second) {
      pair<int, int> new_mx = make_pair(i, num), new_mn;
      int b = 0;
      for (int i = 0; i < 52; ++i)
        if (a[i] && a[i] < a[b] || !a[b]) b = i;
      new_mn = make_pair(a[b], b);
      if (mx.first - mn.first >= new_mx.first - new_mn.first) {
        mx = new_mx;
        mn = new_mn;
      }
    } else {
      pair<int, int> new_mx = make_pair(i, num), new_mn;
      int b = 0;
      for (int i = 0; i < 52; ++i)
        if (a[i] && a[i] < a[b] || !a[b]) b = i;
      new_mn = make_pair(a[b], b);
      if (mx.first - mn.first >= new_mx.first - new_mn.first) {
        mx = new_mx;
        mn = new_mn;
      }
    }
  }
  cout << mx.first - mn.first + 1;
  return 0;
}
