#include <bits/stdc++.h>
using namespace std;
long long findLargestValidSubstring(const string &s, long long k) {
set<char> g;
long long n = s.length();
long long i = 0, j = 0;
long long p = 0;
while (j < n) {
g.insert(s[j]);
char max_char = *(g.rbegin());
char min_char = *(g.begin());
while ((max_char - min_char) > k) {
g.erase(s[i]);
i++;
max_char = *(g.rbegin());
min_char = *(g.begin());
}
p = max(p, j - i + 1);
j++;
}
return p;
}
int main() {
long long k;
string s;
cin >> k;
cin >> s;
cout << findLargestValidSubstring(s, k) << "\n";
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpsb25nIGxvbmcgZmluZExhcmdlc3RWYWxpZFN1YnN0cmluZyhjb25zdCBzdHJpbmcgJnMsIGxvbmcgbG9uZyBrKSB7CiAgICBzZXQ8Y2hhcj4gZzsKICAgIGxvbmcgbG9uZyBuID0gcy5sZW5ndGgoKTsKICAgIGxvbmcgbG9uZyBpID0gMCwgaiA9IDA7CiAgICBsb25nIGxvbmcgcCA9IDA7CgogICAgd2hpbGUgKGogPCBuKSB7CiAgICAgICAgZy5pbnNlcnQoc1tqXSk7CiAgICAgICAgY2hhciBtYXhfY2hhciA9ICooZy5yYmVnaW4oKSk7CiAgICAgICAgY2hhciBtaW5fY2hhciA9ICooZy5iZWdpbigpKTsKCiAgICAgICAgd2hpbGUgKChtYXhfY2hhciAtIG1pbl9jaGFyKSA+IGspIHsKICAgICAgICAgICAgZy5lcmFzZShzW2ldKTsKICAgICAgICAgICAgaSsrOwogICAgICAgICAgICBtYXhfY2hhciA9ICooZy5yYmVnaW4oKSk7CiAgICAgICAgICAgIG1pbl9jaGFyID0gKihnLmJlZ2luKCkpOwogICAgICAgIH0KCiAgICAgICAgcCA9IG1heChwLCBqIC0gaSArIDEpOwogICAgICAgIGorKzsKICAgIH0KCiAgICByZXR1cm4gcDsKfQoKaW50IG1haW4oKSB7CiAgICBsb25nIGxvbmcgazsKICAgIHN0cmluZyBzOwogICAgY2luID4+IGs7CiAgICBjaW4gPj4gczsKICAgIAogICAgY291dCA8PCBmaW5kTGFyZ2VzdFZhbGlkU3Vic3RyaW5nKHMsIGspIDw8ICJcbiI7CgogICAgcmV0dXJuIDA7Cn0K