#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  string minWindow(string &source, string &target) {
    if (source.empty() || source.length() < target.length()) {
      return "";
    }
    const int ASCII_MAX = 256;
    vector<int> exp_cnt(ASCII_MAX, 0);
    vector<int> cur_cnt(ASCII_MAX, 0);
    int cnt = 0;
    int start = 0;
    int min_start = 0;
    int min_width = numeric_limits<int>::max();
    for (const auto &c : target) {
      ++exp_cnt[c];
    }
    for (int i = 0; i < source.length(); ++i) {
      if (exp_cnt[source[i]] > 0) {
        ++cur_cnt[source[i]];
        if (cur_cnt[source[i]] <= exp_cnt[source[i]]) {
          ++cnt;
        }
      }
      if (cnt == target.size()) {
        while (exp_cnt[source[start]] == 0 ||
               cur_cnt[source[start]] > exp_cnt[source[start]]) {
          --cur_cnt[source[start]];
          ++start;
        }
        if (min_width > i - start + 1) {
          min_width = i - start + 1;
          min_start = start;
        }
      }
    }
    if (min_width == numeric_limits<int>::max()) {
      return "";
    }
    return source.substr(min_start, min_width);
  }
};
using namespace std;
int main() {
  long long n;
  cin >> n;
  string s;
  string t = "";
  cin >> s;
  set<char> jarvis;
  for (int i = 0; i < n; i++) jarvis.insert(s[i]);
  for (set<char>::iterator it = jarvis.begin(); it != jarvis.end(); it++)
    t.push_back(*it);
  Solution x;
  string ans = x.minWindow(s, t);
  cout << ans.size();
  return 0;
}
