#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[100300];
void dijkstra_matrix(int graph[1255][1255], int src, int dist[], int V) {
  bool sptSet[V];
  for (int i = 0; i < V; i++) dist[i] = INT_MAX, sptSet[i] = false;
  dist[src] = 0;
  for (int count = 0; count < V - 1; count++) {
    int u;
    int min = INT_MAX, min_index;
    for (int v = 0; v < V; v++)
      if (sptSet[v] == false && dist[v] <= min) min = dist[v], min_index = v;
    u = min_index;
    sptSet[u] = true;
    for (int v = 0; v < V; v++)
      if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX &&
          dist[u] + graph[u][v] < dist[v])
        dist[v] = dist[u] + graph[u][v];
  }
}
void dijkstra_adj(int src, int dist[]) {
  set<pair<int, int> > setds;
  for (int i = 0; i < 100030; ++i) dist[i] = 1002000;
  setds.insert(make_pair(0, src));
  dist[src] = 0;
  while (!setds.empty()) {
    pair<int, int> tmp = *(setds.begin());
    setds.erase(setds.begin());
    int u = tmp.second;
    int i;
    for (i = 0; i < adj[u].size(); ++i) {
      int v = adj[u][i].first;
      int weight = adj[u][i].second;
      if (dist[v] > dist[u] + weight) {
        if (dist[v] != 1002000) setds.erase(setds.find(make_pair(dist[v], v)));
        dist[v] = dist[u] + weight;
        setds.insert(make_pair(dist[v], v));
      }
    }
  }
}
void floyd_warshall(int arr[][105], int n) {
  int i, j, k;
  for (k = 1; k <= n; ++k)
    for (i = 1; i <= n; ++i)
      for (j = 1; j <= n; ++j)
        arr[i][j] = min(arr[i][j], arr[i][k] + arr[k][j]);
}
long long power(long long x, long long y) {
  if (y == 0) return 1;
  long long res = power(x, y / 2);
  if (y & 1) return x * res * res;
  return res * res;
}
vector<int> prime_sieve(int n) {
  int i, j;
  vector<int> arr(n + 1);
  vector<bool> isprime(n + 1, 1);
  for (i = 2; i <= n; ++i)
    if (isprime[i]) {
      arr.push_back(i);
      for (j = 2; j * i <= n; ++j) isprime[i * j] = 0;
    }
  return arr;
}
int main() {
  int i, j, n, m, u, v, t, k, w, x, q;
  cin >> n;
  string s;
  cin >> s;
  t = 0;
  map<char, int> mp, temp;
  for (i = 0; i < n; ++i) {
    if (mp.find(s[i]) == mp.end()) {
      t++;
      mp[s[i]] = 1;
    }
  }
  int ans = INT_MAX;
  k = 0;
  i = 0;
  j = 0;
  while (j < n) {
    while (k < t && j < n) {
      if (temp.find(s[j]) == temp.end()) {
        k++;
        temp[s[j]] = 1;
        if (k == t) break;
      } else
        temp[s[j]]++;
      j++;
    }
    if (j == n) break;
    while (i <= j && temp[s[i]] > 1) {
      temp[s[i]]--;
      i++;
    }
    ans = min(ans, j - i + 1);
    temp.erase(temp.find(s[i]));
    i++;
    k--;
    j++;
  }
  cout << ans;
}
