#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 100;
const int INF = 0x3f3f3f3f;
map<char, int> mp;
int cnt;
int getid(char x) {
  if (mp.count(x)) return mp[x];
  mp[x] = ++cnt;
  return cnt;
}
char s[maxn];
int vis[maxn];
int a[maxn];
int l[60][maxn];
bool check(int x, int y) {
  for (int i = 1; i <= cnt; ++i) {
    if (l[i][y] - l[i][x - 1] < 1) {
      ;
      ;
      ;
      ;
      ;
      return false;
    }
  }
  return true;
}
int main() {
  int n;
  while (cin >> n) {
    scanf("%s", s + 1);
    ;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; ++i) {
      vis[s[i]] = true;
    };
    cnt = 0;
    for (int i = 0; i < 200; ++i) {
      if (vis[i]) {
        vis[i] = ++cnt;
        ;
        ;
        ;
      }
    }
    for (int i = 0; i < 60; ++i) {
      l[i][0] = 0;
    };
    for (int i = 1; i <= n; ++i) {
      a[i] = vis[s[i]];
      ;
      for (int j = 1; j <= cnt; ++j) {
        if (a[i] == j) {
          l[j][i] = l[j][i - 1] + 1;
        } else {
          l[j][i] = l[j][i - 1];
        }
      }
    };
    int ans = n;
    for (int i = 1; i <= n; ++i) {
      int r = n;
      int lll = i;
      while (lll < r) {
        int m = (lll + r) >> 1;
        if (check(i, m))
          r = m;
        else
          lll = m + 1;
      };
      ;
      ;
      if (check(i, lll)) ans = min(ans, lll - i + 1);
    }
    cout << ans << "\n";
  }
  return 0;
}
