#include <bits/stdc++.h>   using namespace std;   long long arr[100005];   long long ans = 0;   long long temp[100005];   bool is(int m, string s) {     set<char> ss;     map<char, int> mp;     for (int i = 0; i < m; i++) {       ss.insert(s[i]);       mp[s[i]]++;     }     if (ss.size() == ans) return true;     for (int i = 0; i <= s.length() - m - 1; i++) {       mp[s[i]]--;       if (mp[s[i]] == 0) ss.erase(s[i]);       ss.insert(s[i + m]);       mp[s[i + m]]++;       if (ss.size() == ans) {         return true;       }     }     return false;   }   int main() {     int n;     string s;     cin >> n >> s;     set<char> se;     for (char c : s) se.insert(c);     ans = se.size();     int l = 0;     int r = n + 1;     while (r - l > 1) {       int m = l + (r - l) / 2;       if (!is(m, s))         l = m;       else         r = m;     }     cout << r << endl;     return 0;   }   