#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const int inf = ((1LL << 29) - 10);
const long long mod = 1000000007;
int vis[maxn];
int num[maxn];
int pos[maxn];
int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  int ansr = inf;
  int cnt = 0;
  memset(vis, 0, sizeof(vis));
  memset(num, 0, sizeof(num));
  memset(pos, -1, sizeof(pos));
  for (int i = 0; i < n; i++) {
    if (!vis[s[i]]) cnt++;
    vis[s[i]] = 1;
  }
  int sum = 0;
  int mx = inf;
  for (int i = 0; i < n; i++) {
    pos[s[i]] = max(pos[s[i]], i);
    if (!num[s[i]]) {
      sum++;
      num[s[i]] = 1;
    }
    int minn = mod;
    for (int j = 65; j < 123; j++) {
      if (pos[j] != -1) minn = min(minn, pos[j]);
    }
    mx = minn;
    if (sum >= cnt) {
      ansr = min(ansr, i - mx + 1);
    }
  }
  cout << ansr << endl;
}
