#include <bits/stdc++.h>
using namespace std;
struct node {
  long long a, b;
  bool operator<(const node &n) const { return a > n.a; }
};
struct node2 {
  long long a, b;
  bool operator<(const node2 &n) const { return a > n.a; }
};
long long n, m, k;
vector<long long> v, v2, v3, v4;
vector<char> vc;
vector<string> vs, vs2;
string s, s2, s3;
vector<node> vn;
vector<long long> G[1005];
map<char, vector<long long> > mpv;
map<char, int> mpc;
int par[105];
int ran[105];
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    ran[i] = 0;
  }
}
int findd(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = findd(par[x]);
  }
}
void unite(int x, int y) {
  x = findd(x);
  y = findd(y);
  if (x == y) return;
  if (ran[x] < ran[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (ran[x] == ran[y]) ran[x]++;
  }
}
bool same(int x, int y) { return findd(x) == findd(y); }
struct edge {
  int u, v;
};
long long dp[100005][2];
int main() {
  long long t, t2, t3;
  while (cin >> n >> s) {
    mpc.clear();
    mpv.clear();
    char c = s[0];
    long long cnt = 0;
    for (int i = 0; i < s.size(); i++) {
      if (mpc[s[i]] == 0) {
        mpv[s[i]].push_back(i);
        mpc[s[i]] = 1;
        cnt++;
      } else
        mpv[s[i]].push_back(i);
    }
    map<char, int> mpcc;
    long long minn = 1e15;
    for (map<char, vector<long long> >::iterator it = mpv.begin();
         it != mpv.end(); it++) {
      if (it->second.size() < minn) {
        c = it->first;
        minn = it->second.size();
      }
      sort(it->second.begin(), it->second.end());
    }
    int sum = 0;
    int p = 0;
    int ans = INT_MAX;
    for (int i = 0; i < s.size(); i++) {
      if (mpcc[s[i]] == 0) sum++;
      mpcc[s[i]]++;
      if (sum == cnt) {
        while (p < i) {
          mpcc[s[p]]--;
          if (mpcc[s[p]] == 0) {
            sum--;
            break;
          }
          p++;
        }
        ans = min(ans, i - p + 1);
        if (p != i)
          p++;
        else
          break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
