#include <iostream>
#include <set>
#include <string>
using namespace std;

int main() {
	// your code goes here
	int n , k;
	cin>>n;
	cin>>k;
	string s;
	cin>>s;
	multiset<char> st;
	int p = 0;
	for(int i = 0, j = 0;j<n ; j++){
		st.insert(s[j]);
		int diff = *st.rbegin() - *st.begin();
		while(diff>k){
			st.erase(s[i]);
			i++;  
            if (!st.empty()) {
                diff = *st.rbegin() - *st.begin();  
            }
		}
		int length = j - i + 1;
        p = max(p, length);
	}
	cout<<p<<endl;
	return 0;
}