#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[55][100010];
int b[55];
string s;
int ans, tmin, tmax;
int main() {
  while (cin >> n) {
    cin >> s;
    memset(b, 0, sizeof(b));
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; ++i) {
      if (s[i] >= 'a' && s[i] <= 'z')
        m = s[i] - 'a';
      else
        m = 26 + s[i] - 'A';
      a[m][b[m]++] = i + 1;
    }
    tmax = n;
    for (int i = 0; i < 52; ++i) {
      if (a[i][b[i] - 1]) {
        tmax = min(tmax, a[i][b[i] - 1]);
      }
    }
    memset(b, 0, sizeof(b));
    tmin = 0;
    for (int i = 0; i < 52; ++i) tmin = max(tmin, a[i][0]);
    ans = tmin;
    for (int i = 1; i < tmax; ++i) {
      if (s[i - 1] >= 'a' && s[i - 1] <= 'z')
        m = s[i - 1] - 'a';
      else
        m = 26 + s[i - 1] - 'A';
      b[m]++;
      tmin = max(tmin, a[m][b[m]]);
      ans = min(ans, tmin - i);
    }
    cout << ans << endl;
  }
  return 0;
}
