#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  map<char, int> m;
  set<char> dis;
  int n;
  cin >> n;
  string s, s2;
  cin >> s;
  s2 = s;
  reverse(s2.begin(), s2.end());
  int res = INT_MAX;
  for (int i = 0; i < s.size(); ++i) {
    dis.insert(s[i]);
  }
  int tot = dis.size();
  int l = 0, r = 0;
  while (r < n) {
    if (m.size() == tot) {
      res = min(res, r - l);
      while (m.size() == tot) {
        res = min(res, r - l);
        m[s[l]]--;
        if (m[s[l]] == 0) m.erase(s[l]);
        l++;
      }
    } else {
      m[s[r]]++;
      r++;
    }
  }
  if (m.size() == tot) {
    res = min(res, n - l);
    while (m.size() == tot) {
      res = min(res, n - l);
      m[s[l]]--;
      if (m[s[l]] == 0) m.erase(s[l]);
      l++;
    }
  }
  r = 0;
  l = 0;
  m.clear();
  while (r < n) {
    if (m.size() == tot) {
      res = min(res, r - l);
      while (m.size() == tot) {
        res = min(res, r - l);
        m[s2[l]]--;
        if (m[s2[l]] == 0) m.erase(s2[l]);
        l++;
      }
    } else {
      m[s2[r]]++;
      r++;
    }
  }
  if (m.size() == tot) {
    res = min(res, n - l);
    while (m.size() == tot) {
      res = min(res, n - l);
      m[s2[l]]--;
      if (m[s2[l]] == 0) m.erase(s2[l]);
      l++;
    }
  }
  cout << res;
  return 0;
}
