#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int inf = 1000000005;
const long long mod = 1000000007;
int vis[100];
char s[100005];
int main() {
  int n, i, j;
  cin >> n >> s + 1;
  int num = 0;
  for (i = 1; i <= n; ++i) {
    if (!vis[s[i] - 'A']) {
      num++;
      vis[s[i] - 'A'] = 1;
    }
  }
  int ans = n;
  int le = 1;
  int ss = 0;
  memset(vis, 0, sizeof(vis));
  for (i = 1; i <= n; ++i) {
    if (vis[s[i] - 'A'] == 0) {
      ss++;
    }
    vis[s[i] - 'A']++;
    while (ss == num) {
      ans = min(ans, i - le + 1);
      vis[s[le] - 'A']--;
      if (vis[s[le] - 'A'] == 0) {
        ss--;
      }
      le++;
    }
  }
  cout << ans << endl;
}
