#include<iostream>
#include<string>
#include<vector>
using namespace std;
int n,m;
string str;//全局变量;
int change(char ch){
vector<int>loc;
for(int i=0;i<n;i++){if(str[i]==ch) loc.push_back(i);}//将与字符相同的下标存入vector;
loc.push_back(n);
int maxlen=loc[m];//loc中存的索引其实是操作m次时的最大长度;
for(int j=m+1;j<loc.size();j++){
maxlen=max(maxlen, loc[j]-loc[j-m-1]-1);
}
return maxlen;
}
int main(){
cin>>n>>m;
cin>>str;
cout<<max(change('a'),change('b'))<<endl;
}