#include <bits/stdc++.h>
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  std::cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
std::pair<int, int> operator+(std::pair<int, int> a, std::pair<int, int> b) {
  return {a.first + b.first, a.second + b.second};
}
std::pair<long long, long long> operator+(std::pair<long long, long long> a,
                                          std::pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
std::ostream& operator<<(std::ostream& out, std::pair<int, int> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::ostream& operator<<(std::ostream& out, std::pair<long long, long long> a) {
  out << a.first << " " << a.second << "\n";
  return out;
}
std::istream& operator>>(std::istream& in, std::pair<int, int>& a) {
  in >> a.first >> a.second;
  return in;
}
std::istream& operator>>(std::istream& in, std::pair<long long, long long>& a) {
  in >> a.first >> a.second;
  return in;
}
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt[n][100];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 100; ++j) {
      cnt[i][j] = 0;
    }
  }
  set<int> ind;
  for (int i = 0; i < n; ++i) {
    cnt[i][s[i] - 'A']++;
    ind.insert(s[i] - 'A');
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 100; ++j) {
      cnt[i][j] += cnt[i - 1][j];
    }
  }
  int low = 1, high = n;
  int mid;
  while (high - low > 1) {
    mid = low + (high - low) / 2;
    int flag = 1;
    for (auto& a : ind) {
      if (cnt[mid - 1][a] == 0) flag = 0;
    }
    if (flag == 1) {
      high = mid;
      continue;
    }
    for (int i = 0; i < n - mid; ++i) {
      flag = 1;
      for (auto& a : ind) {
        if (cnt[i + mid][a] - cnt[i][a] == 0) flag = 0;
      }
      if (flag == 1) {
        high = mid;
        goto x;
      }
    }
    low = mid + 1;
  x:;
  }
  int flag = 1;
  for (auto& a : ind) {
    if (cnt[low - 1][a] == 0) flag = 0;
  }
  if (flag == 1) {
    cout << low << "\n";
    return 0;
  }
  for (int i = 0; i < n - low; ++i) {
    flag = 1;
    for (auto& a : ind) {
      if (cnt[i + low][a] - cnt[i][a] == 0) flag = 0;
    }
    if (flag == 1) {
      cout << low << "\n";
      return 0;
    }
  }
  cout << high << "\n";
  return 0;
}
