#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
struct child {
  long long v1, v2, con;
};
int convert(char c) {
  if (c >= 'a' && c <= 'z') {
    return c - 'a';
  } else {
    return c - 'A' + 26;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int arr[s.size()][52];
  long long res = 1000000000000000000;
  long long tmp = 0;
  set<char> sett;
  for (int i = 0; i < n; i++) {
    sett.insert(s[i]);
  }
  int diff = sett.size();
  for (int i = 0; i < 52; i++) {
    arr[0][i] = -1;
  }
  arr[0][convert(s[0])] = 0;
  for (int i = 0; i < s.size(); i++) {
    if (i > 0) {
      for (int ii = 0; ii < 52; ii++) {
        arr[i][ii] = arr[i - 1][ii];
      }
      int num = convert(s[i]);
      arr[i][num] = i;
    }
    int cnt = 0;
    long long mn = 1000000000000000000;
    for (int ii = 0; ii < 52; ii++) {
      if (arr[i][ii] != -1) {
        cnt++;
        mn = min(mn, (long long)arr[i][ii]);
      }
    }
    if (cnt == diff) {
      res = min(res, (long long)i - mn + 1);
    }
  }
  cout << res << endl;
  return 0;
}
