#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>

using namespace std;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const ll base = 1000 * 1000 * 1000 + 7;

const int maxn = 1000 * 1000 + 5;
char s[maxn];
int pref_B[maxn], pref_W[maxn], pref_X[maxn];

int L[maxn], R[maxn];
ll Lc[maxn], Rc[maxn], bpow[maxn];

ll dyn_B[maxn], dyn_W[maxn];

int n, k;

inline int sum_B(int l, int r)
{
	if (l > r) {
		return 0;
	}
	return pref_B[r] - (l ? pref_B[l - 1] : 0);
}

inline int sum_W(int l, int r)
{
	if (l > r) {
		return 0;
	}
	return pref_W[r] - (l ? pref_W[l - 1] : 0);
}

inline int sum_X(int l, int r)
{
	if (l > r) {
		return 0;
	}
	return pref_X[r] - (l ? pref_X[l - 1] : 0);
}

void init_dyn()
{
	dyn_B[0] = 1;
	ll sum = dyn_B[0];
	int last = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'B') {
			dyn_B[i + 1] = 0;
		}
		else {
			dyn_B[i + 1] = sum;
		}
		sum += dyn_B[i + 1];
		if (i - (k - 1) >= last) {
			sum -= dyn_B[i - (k - 1)] - base;
			++last;
		}
		sum %= base;
		if (s[i] == 'W') {
			sum = dyn_B[i + 1];
			last = i + 1;
		}
		//cout << dyn_B[i + 1] << endl;
	}

	dyn_W[0] = 1;
	sum = dyn_W[0];
	last = 0;
	for (int i = 0; i < n; ++i) {
		if (s[n - i - 1] == 'W') {
			dyn_W[i + 1] = 0;
		}
		else {
			dyn_W[i + 1] = sum;
		}
		sum += dyn_W[i + 1];
		if (i - (k - 1) >= last) {
			sum -= dyn_W[i - (k - 1)] - base;
			++last;
		}
		sum %= base;
		if (s[n - i - 1] == 'B') {
			sum = dyn_W[i + 1];
			last = i + 1;
		}
		//cout << dyn_W[i + 1] << endl;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d%d\n", &n, &k);
	scanf("%s\n", s);
	init_dyn();

	for (int i = 0; i < n; ++i) {
		bpow[i] = (i ? (bpow[i - 1] * 2) : 1) % base;
	}

	int l_cnt = 0, r_cnt = 0;
	for (int i = 0; i < n; ++i) {
		pref_B[i] = (i ? pref_B[i - 1] : 0) + (s[i] == 'B');
		pref_W[i] = (i ? pref_W[i - 1] : 0) + (s[i] == 'W');
		pref_X[i] = (i ? pref_X[i - 1] : 0) + (s[i] == 'X');
	}

	for (int i = 0; i < n - k + 1; ++i) {
		if (sum_W(i, i + k - 1)) {
			continue;
		}

		L[l_cnt] = i;
		Lc[l_cnt++] = dyn_B[i];

		if (!sum_X(i, i + k - 1)) {
			break;
		}
	}

	for (int i = n - k; i >= 0; --i) {
		if (sum_B(i, i + k - 1)) {
			continue;
		}

		R[r_cnt] = i;
		Rc[r_cnt++] = dyn_W[n - (i + k - 1) - 1];

		if (!sum_X(i, i + k - 1)) {
			break;
		}
	}

	/*for (int i = 0; i < l_cnt; ++i) {
		cout << "(" << L[i] << "; " << Lc[i] << ") ";
	}
	cout << "\n";
	for (int i = 0; i < r_cnt; ++i) {
		cout << "(" << R[i] << "; " << Rc[i] << ") ";
	}
	cout << "\n";*/

	/*ll res = 0;
	for (int l = 0; l < l_cnt; ++l) {
		for (int r = 0; r < r_cnt; ++r) {
			if (L[l] + k <= R[r]) {

				res += Lc[l] * Rc[r] * bpow[sum_X(L[l] + k, R[r] - 1)];
				cout << L[l] << " " << R[r] << " " << Lc[l] * Rc[r] * bpow[sum_X(L[l] + k, R[r] - 1)] << " " << res << endl;
			}
		}
	}*/

	ll res = 0;
	ll last = 0;
	int r = 0;
	for (int l = l_cnt - 1; l >= 0; --l) {
		if (l != l_cnt - 1) {
			 last *= bpow[sum_X(L[l] + k, L[l + 1] + k - 1)];
			 last %= base;
		}

		while (r < r_cnt && L[l] + k <= R[r]) {
			last += Rc[r] * bpow[sum_X(L[l] + k, R[r] - 1)];
			last %= base;
			++r;
		}

		res += (last * Lc[l]) % base;
		res %= base;
	}

	cout << res;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <list>

using namespace std;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const ll base = 1000 * 1000 * 1000 + 7;

const int maxn = 1000 * 1000 + 5;
char s[maxn];
int pref_B[maxn], pref_W[maxn], pref_X[maxn];

int L[maxn], R[maxn];
ll Lc[maxn], Rc[maxn], bpow[maxn];

ll dyn_B[maxn], dyn_W[maxn];

int n, k;

inline int sum_B(int l, int r)
{
	if (l > r) {
		return 0;
	}
	return pref_B[r] - (l ? pref_B[l - 1] : 0);
}

inline int sum_W(int l, int r)
{
	if (l > r) {
		return 0;
	}
	return pref_W[r] - (l ? pref_W[l - 1] : 0);
}

inline int sum_X(int l, int r)
{
	if (l > r) {
		return 0;
	}
	return pref_X[r] - (l ? pref_X[l - 1] : 0);
}

void init_dyn()
{
	dyn_B[0] = 1;
	ll sum = dyn_B[0];
	int last = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'B') {
			dyn_B[i + 1] = 0;
		}
		else {
			dyn_B[i + 1] = sum;
		}
		sum += dyn_B[i + 1];
		if (i - (k - 1) >= last) {
			sum -= dyn_B[i - (k - 1)] - base;
			++last;
		}
		sum %= base;
		if (s[i] == 'W') {
			sum = dyn_B[i + 1];
			last = i + 1;
		}
		//cout << dyn_B[i + 1] << endl;
	}

	dyn_W[0] = 1;
	sum = dyn_W[0];
	last = 0;
	for (int i = 0; i < n; ++i) {
		if (s[n - i - 1] == 'W') {
			dyn_W[i + 1] = 0;
		}
		else {
			dyn_W[i + 1] = sum;
		}
		sum += dyn_W[i + 1];
		if (i - (k - 1) >= last) {
			sum -= dyn_W[i - (k - 1)] - base;
			++last;
		}
		sum %= base;
		if (s[n - i - 1] == 'B') {
			sum = dyn_W[i + 1];
			last = i + 1;
		}
		//cout << dyn_W[i + 1] << endl;
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d%d\n", &n, &k);
	scanf("%s\n", s);
	init_dyn();

	for (int i = 0; i < n; ++i) {
		bpow[i] = (i ? (bpow[i - 1] * 2) : 1) % base;
	}

	int l_cnt = 0, r_cnt = 0;
	for (int i = 0; i < n; ++i) {
		pref_B[i] = (i ? pref_B[i - 1] : 0) + (s[i] == 'B');
		pref_W[i] = (i ? pref_W[i - 1] : 0) + (s[i] == 'W');
		pref_X[i] = (i ? pref_X[i - 1] : 0) + (s[i] == 'X');
	}

	for (int i = 0; i < n - k + 1; ++i) {
		if (sum_W(i, i + k - 1)) {
			continue;
		}

		int last_cnt_X = i ? sum_X(0, i - 1) : 0;
		L[l_cnt] = i;
		Lc[l_cnt] = (dyn_B[i] + base) % base;

		if (!sum_X(i, i + k - 1)) {
			break;
		}
	}

	for (int i = n - k; i >= 0; --i) {
		if (sum_B(i, i + k - 1)) {
			continue;
		}

		int last_cnt_X = (i < n - 1) ? sum_X(i + 1, n - 1) : 0;
		R[r_cnt] = i;
		Rc[r_cnt] = (dyn_W[n - (i + k - 1) - 1] + base) % base;

		if (!sum_X(i, i + k - 1)) {
			break;
		}
	}

	/*for (int i = 0; i < l_cnt; ++i) {
		cout << "(" << L[i] << "; " << Lc[i] << ") ";
	}
	cout << "\n";
	for (int i = 0; i < r_cnt; ++i) {
		cout << "(" << R[i] << "; " << Rc[i] << ") ";
	}
	cout << "\n";*/

	/*ll res = 0;
	for (int l = 0; l < l_cnt; ++l) {
		for (int r = 0; r < r_cnt; ++r) {
			if (L[l] + k <= R[r]) {

				res += Lc[l] * Rc[r] * bpow[sum_X(L[l] + k, R[r] - 1)];
				cout << L[l] << " " << R[r] << " " << Lc[l] * Rc[r] * bpow[sum_X(L[l] + k, R[r] - 1)] << " " << res << endl;
			}
		}
	}*/

	ll res = 0;
	ll last = 0;
	int r = 0;
	for (int l = l_cnt - 1; l >= 0; --l) {
		if (l != l_cnt - 1) {
			 last *= bpow[sum_X(L[l] + k, L[l + 1] + k - 1)];
			 last %= base;
		}

		while (r < r_cnt && L[l] + k <= R[r]) {
			last += Rc[r] * bpow[sum_X(L[l] + k, R[r] - 1)];
			last %= base;
			++r;
		}

		res += (last * Lc[l]) % base;
		res %= base;
	}

	cout << res;

	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int N = int(1e6)+10;
const int mod = int(1e9)+7;
char ch[N];
ll nearb[N],neara[N],sumb[N][2],haveb[N][2],all[N],dp[N][2],sum[N][2];
int main(){
    int n,k;
    #define havab haveb
    while(~scanf("%d%d",&n,&k)){
        scanf("%s",ch);
        all[0]=1;
        for(int i=1;i<=n;i++){
            char x = ch[i-1];
            if(x == 'B') nearb[i] = i, neara[i] = neara[i-1];
            else if(x == 'W') nearb[i] = nearb[i-1], neara[i] = i;
            else nearb[i] = nearb[i-1] , neara[i] = neara[i-1];
            if(x == 'X') all[i] = (all[i-1] <<1) % mod;
            else all[i] = all[i-1];
            int j= neara[i],p = i - k;
            if(p < j) p = j-1;
            if(p<0) p=0;
            if(x == 'W') {
                haveb[i][1] = 0;
                haveb[i][0] = (havab[i-1][0] + havab[i-1][1]) % mod;
            }
            else {
                if(x == 'B') havab[i][0] = 0;
                else havab[i][0] = (havab[i-1][0] + havab[i-1][1]) % mod;
                havab[i][1] = (sumb[i-1][0] - sumb[p][0] + mod) % mod;
                if(i-j>=k) {
                    havab[i][1] += all[p];
                    havab[i][1] %= mod;
                }
            }
//            cout<<"i: "<<i<<" "<<haveb[i][0]<<" "<<haveb[i][1]<<endl;
            sumb[i][0] = (sumb[i-1][0] + haveb[i][0] ) % mod;
            sumb[i][1] = (sumb[i-1][1] + haveb[i][1] ) % mod;
            j = nearb[i];
            p = i - k;
            if(p < j) p = j-1;
            if(p<0) p=0;
            if(x == 'B') {
                dp[i][0] = 0;
                dp[i][1] = (dp[i-1][0] + dp[i-1][1]) % mod;
            }
            else {
                if(x == 'W') dp[i][1] = 0;
                else dp[i][1] = (dp[i-1][0] + dp[i-1][1]) % mod;
                dp[i][0] = (sum[i-1][1] - sum[p][1] + mod) % mod;
                if(i-j>=k) {
                    dp[i][0] += sumb[p][1] - sumb[j-1][1] + mod;
                    dp[i][0] %= mod;
                }
            }
//            cout<<j<<" "<<p<<endl;
//            cout<<"dp: "<<dp[i][0]<<" "<<dp[i][1]<<endl;
            sum[i][0] = (sum[i-1][0] + dp[i][0]) % mod;
            sum[i][1] = (sum[i-1][1] + dp[i][1]) % mod;
        }
        cout<<(dp[n][0] + dp[n][1]) % mod <<endl;
    }
}


/**
 *       Compiler:  gcc
 *         Author:  bdep__
 *        Created:  07/29/2012 11:01:58 AM
 ***/

#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <iostream>
#include <algorithm>
#define N 1000010
#define M 1000010
#define S 1000100
#define eps 1e-8
#define inf 0x3fffffff
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define SZ(a) ((int)((a).size()))
#define ALL(a) (a).begin(),(a).end()
#define CLR(a,x) memset(a,x,sizeof(a))

typedef long long LL;
using namespace std;

char s[N];
LL nob[N],now[N],dpb[N],dpw[N],cntb[N],cntw[N];
int n,k;

void init()
{
	cntb[0]=cntw[n]=0;
	for(int i=1; i<=n; i++)
		cntb[i]=cntb[i-1]+(s[i-1]=='B');
	for(int i=n-1; i>=0; i--)
		cntw[i]=cntw[i+1]+(s[i]=='W');
	nob[0]=now[n]=1;
	LL two=1;
	for(int i=1; i<=n; i++)
	{
		dpb[i]=0;
		if(i>=k&&cntw[i]==cntw[i-k])
		{
			if(i==k||s[i-k-1]!='B')
				dpb[i]=nob[max(i-k-1,0)];
		}
		two=1;
		if(s[i-1]=='X')
			two=2;
		nob[i]=(nob[i-1]*two-dpb[i])%MOD;
	}
	for(int i=n-1; i>=0; i--)
	{
		dpw[i]=0;
		if(i+k<=n&&cntb[i]==cntb[i+k])
		{
			if(i+k==n||s[i+k]!='W')
				dpw[i]=now[min(n,i+k+1)];
		}
		two=1;
		if(s[i]=='X')
			two=2;
		now[i]=(now[i+1]*two-dpw[i])%MOD;
	}
}

int main()
{
	while(scanf("%d%d%s",&n,&k,s)!=EOF)
	{
		init();
		LL ret=0,two=1,tmp;
		for(int i=0; i<n; i++)
		{
			if(s[i]=='X')
				two=(two*2)%MOD;
			tmp=(two-nob[i+1])%MOD;
			ret=(ret+tmp*dpw[i+1])%MOD;
		}
		cout<<ret<<endl;
	}
	return 0;
}


/**
 *       Compiler:  gcc
 *         Author:  bdep__
 *        Created:  07/29/2012 11:01:58 AM
 ***/

#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <iostream>
#include <algorithm>
#define N 1000010
#define M 1000010
#define S 1000100
#define eps 1e-8
#define inf 0x3fffffff
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define SZ(a) ((int)((a).size()))
#define ALL(a) (a).begin(),(a).end()
#define CLR(a,x) memset(a,x,sizeof(a))

typedef long long LL;
using namespace std;

char s[N];
LL nob[N],now[N],dpb[N],dpw[N],cntb[N],cntw[N];
int n,k;

void init()
{
	cntb[0]=cntw[n]=0;
	for(int i=1; i<=n; i++)
		cntb[i]=cntb[i-1]+(s[i-1]=='B');
	for(int i=n-1; i>=0; i--)
		cntw[i]=cntw[i+1]+(s[i]=='W');
	nob[0]=now[n]=1;
	LL two=1;
	for(int i=1; i<=n; i++)
	{
		dpb[i]=0;
		if(i>=k&&cntw[i]==cntw[i-k])
		{
			if(i==k||s[i-k-1]!='B')
				dpb[i]=nob[max(i-k-1,0)];
		}
		two=1;
		if(s[i-1]=='X')
			two=2;
		nob[i]=(nob[i-1]*two-dpb[i])%MOD;
	}
	for(int i=n-1; i>=0; i--)
	{
		dpw[i]=0;
		if(i+k<=n&&cntb[i]==cntb[i+k])
		{
			if(i+k==n||s[i+k]!='W')
				dpw[i]=now[min(n,i+k+1)];
		}
		two=1;
		if(s[i]=='X')
			two=2;
		now[i]=(now[i+1]*two-dpw[i])%MOD;
	}
}

int main()
{
	while(scanf("%d%d%s",&n,&k,s)!=EOF)
	{
		init();
		LL ret=0,two=1,tmp;
		for(int i=0; i<n; i++)
		{
			if(s[i]=='X')
				two=(two*2)%MOD;
			tmp=two-nob[i+1];
			ret=(ret+tmp*dpw[i+1])%MOD;
		}
		cout<<ret<<endl;
	}
	return 0;
}


/**
 *       Compiler:  gcc
 *         Author:  bdep__
 *        Created:  07/29/2012 11:01:58 AM
 ***/

#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <iostream>
#include <algorithm>
#define N 1000010
#define M 1000010
#define S 1000100
#define eps 1e-8
#define inf 0x3fffffff
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define SZ(a) ((int)((a).size()))
#define ALL(a) (a).begin(),(a).end()
#define CLR(a,x) memset(a,x,sizeof(a))

typedef long long LL;
using namespace std;

char s[N];
LL nob[N],now[N],dpb[N],dpw[N],cntb[N],cntw[N];
int n,k;

void init()
{
	cntb[0]=cntw[n]=0;
	for(int i=1; i<=n; i++)
		cntb[i]=cntb[i-1]+(s[i-1]=='B');
	for(int i=n-1; i>=0; i--)
		cntw[i]=cntw[i+1]+(s[i]=='W');
	nob[0]=now[n]=1;
	LL two=1;
	for(int i=1; i<=n; i++)
	{
		dpb[i]=0;
		if(i>=k&&cntw[i]==cntw[i-k])
		{
			if(i==k||s[i-k-1]!='B')
				dpb[i]=nob[max(i-k-1,0)];
		}
		two=1;
		if(s[i-1]=='X')
			two=2;
		nob[i]=(nob[i-1]*two-dpb[i])%MOD;
	}
	for(int i=n-1; i>=0; i--)
	{
		dpw[i]=0;
		if(i+k<=n&&cntb[i]==cntb[i+k])
		{
			if(i+k==n||s[i+k]!='W')
				dpw[i]=now[min(n,i+k+1)];
		}
		two=1;
		if(s[i]=='X')
			two=2;
		now[i]=(now[i+1]*two-dpw[i])%MOD;
	}
}

int main()
{
	while(scanf("%d%d%s",&n,&k,s)!=EOF)
	{
		init();
		LL ret=0,two=1,tmp;
		for(int i=0; i<n; i++)
		{
			if(s[i]=='X')
				two=(two*2)%MOD;
			tmp=(two-nob[i+1])%MOD;
			ret=(ret+tmp*dpw[i+1])%MOD;
		}
		cout<<(ret%MOD+MOD)%MOD<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <algorithm>
#include <iterator>
#include <numeric>
#include <functional>
#include <iomanip>

using namespace std;

typedef long long int ll;
typedef long double ld;

const int SIZE = 10;
const ll MOD = (int)1e9 + 7;
const int MAXM = 2000;
const int STRSIZE = 10;
const int INF = (int)1e9 + 7;
const ld PI = acosl(-1);

int main()
{
#ifdef _CONSOLE
    freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);

	int n, k;

	cin >> n >> k;

	string s;

	cin >> s;

	int a = 0, b = 0;
	int l = 0, r = 0;
	int max = 0;

	while (r < s.size()) {
		if (s[r] == 'a')
			a++;
		else
			b++;

		r++;

		while (b > k) {
			if (s[l] == 'a')
				a--;
			else
				b--;

			l++;
		}

		if (r - l > max)
			max = r - l;
	}

	while (r < s.size()) {
		if (s[r] == 'a')
			a++;
		else
			b++;

		r++;

		while (a > k) {
			if (s[l] == 'a')
				a--;
			else
				b--;

			l++;
		}

		if (r - l > max)
			max = r - l;
	}

	cout << max << endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <algorithm>
#include <iterator>
#include <numeric>
#include <functional>
#include <iomanip>

using namespace std;

typedef long long int ll;
typedef long double ld;

const int SIZE = 10;
const ll MOD = (int)1e9 + 7;
const int MAXM = 2000;
const int STRSIZE = 10;
const int INF = (int)1e9 + 7;
const ld PI = acosl(-1);

int main()
{
#ifdef _CONSOLE
    freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);

	int n, k;

	cin >> n >> k;

	string s;

	cin >> s;

	int a = 0, b = 0;
	int l = 0, r = 0;
	int max = 0;

	while (r < s.size()) {
		if (s[r] == 'a')
			a++;
		else
			b++;

		r++;

		while (b > k) {
			if (s[l] == 'a')
				a--;
			else
				b--;

			l++;
		}

		if (r - l > max)
			max = r - l;
	}

	l = r = 0;

	while (r < s.size()) {
		if (s[r] == 'a')
			a++;
		else
			b++;

		r++;

		while (a > k) {
			if (s[l] == 'a')
				a--;
			else
				b--;

			l++;
		}

		if (r - l > max)
			max = r - l;
	}

	cout << max << endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <algorithm>
#include <iterator>
#include <numeric>
#include <functional>
#include <iomanip>

using namespace std;

typedef long long int ll;
typedef long double ld;

const int SIZE = 10;
const ll MOD = (int)1e9 + 7;
const int MAXM = 2000;
const int STRSIZE = 10;
const int INF = (int)1e9 + 7;
const ld PI = acosl(-1);

int main()
{
#ifdef _CONSOLE
    freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);

	int n, k;

	cin >> n >> k;

	string s;

	cin >> s;

	int a = 0, b = 0;
	int l = 0, r = 0;
	int max = 0;

	while (r < s.size()) {
		if (s[r] == 'a')
			a++;
		else
			b++;

		r++;

		while (b > k) {
			if (s[l] == 'a')
				a--;
			else
				b--;

			l++;
		}

		if (r - l > max)
			max = r - l;
	}

	l = r = 0;
	a = b = 0;

	while (r < s.size()) {
		if (s[r] == 'a')
			a++;
		else
			b++;

		r++;

		while (a > k) {
			if (s[l] == 'a')
				a--;
			else
				b--;

			l++;
		}

		if (r - l > max)
			max = r - l;
	}

	cout << max << endl;
}


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

const int maxn = 1e5 + 7;

int solve(int mas[], int n, int k, int bit)
{
	int left = 1;
	int right = 1;
	int answer = 0;
	while(left != n + 1)
	{
		while(right != n + 1 && (k || mas[right] != bit))
		{
			if(mas[right] == bit && k)
				k--;
			right++;
			continue;
		}
		if(right - left > answer)
			answer = right - left;
		if(mas[left] == bit)
			k++;
		left++;
		continue;
	}
	return answer;
}

int main()
{
	int n, k;
	int mas[maxn] = {0};
	int answer = -1;
	string str;
	cin >> n >> k;
	cin >> str;
	for(int i = 0; i < str.length(); i++)
		mas[i + 1] = str[i] - 'a';
	answer = max(solve(mas, n, k, 1), solve(mas, n, k, 0));
	cout << answer << endl;
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
//#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

//#pragma comment(linker,"/STACK:102400000,102400000")
#define MEM0(a) (memset((a),0,sizeof(a)))
#define MEMf1(a) (memset((a),-1,sizeof(a)))
#define MEM1(a) (memset((a),1,sizeof(a)))
#define LEN(a) (int)strlen((a))
#define sfd(a) scanf("%d",&(a))
#define sf64d(a) scanf("%I64d",&(a))
#define sflf(a) scanf("%lf",&(a))
#define sfc(a) scanf("%c",&(a))
#define sf2d(a,b) scanf("%d%d",&(a),&(b))
#define sf3d(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sf2lf(a,b) scanf("%lf%lf",&(a),&(b))
#define sf3lf(a,b,c) scanf("%lf%lf%lf",&(a),&(b),&(c))
#define sf264d(a,b) scanf("%I64d%I64d",&(a),&(b))
#define sf364d(a,b,c) scanf("%I64d%I64d%I64d",&(a),&(b),&(c))
#define pfd(a) printf("%d\n",(a))
#define pfc(a) printf("%c",(a));
#define pf64d(a) printf("%I64d\n",(a))
#define pff(a) printf("%f\n",(a))
#define pfs(a) printf("%s\n",(a))
#define pf2d(a,b) printf("%d %d\n",(a),(b))
#define pf2s(a,b) printf("%s %s\n",(a),(b));
#define pf2f(a,b) printf("%f %f\n",(a),(b))
#define pf264d(a,b) printf("%I64d %I64d\n",(a),(b))
#define pfn printf("\n")
#define pfblank printf(" ")
#define LL long long
#define INT_MAX 2147483647
const int MOD = 1000000007;
const int INF = 0x7fffffff;

const int dir4[4][2] = { { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 } };
const int dir8[8][2] = { { -1,0 },{ -1,1 },{ 0,1 },{ 1,1 },{ 1,0 },{ 1,-1 },{ 0,-1 },{ -1,-1 } };

const double eps = 1e-8; const double PI = acos(-1.0);
inline int sign(double x) { return (x>eps) - (x<-eps); }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
/*************************/

int a_count=0, b_count=0;
int apos[100000], bpos[100000];
int main() {
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	int n, k;
	char in[100000];
	sf2d(n,k);

	int at = 1, bt = 1;

	apos[0] = bpos[0] = 0;

	for (int z = 0; z < n; z++) {
		sfc(in[z]);

		if (in[z] == 'a') {
			a_count++;
			apos[at] = z+1;
			at++;
		}
		else if(in[z]=='b'){
			b_count++;
			bpos[bt] = z+1;
			bt++;
		}
		else {
			z--;
		}
	}

	int ans=0,temp;
	if (k >= Min(a_count, b_count)) {
		cout << n << endl;
	}
	else if (b_count < a_count) {
		for (int i = k; i <= b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - bpos[b_count - k];
		ans = Max(temp, ans);
		cout << ans << endl;
	}
	else if (a_count < b_count) {
		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - apos[a_count - k];
		ans = Max(temp, ans);
		cout << ans << endl;
	}
	else {
		for (int i = k; i <= b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - bpos[b_count - k];
		ans = Max(temp, ans);

		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - apos[a_count - k];
		ans = Max(temp, ans);

		cout << ans << endl;
	}
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
//#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

//#pragma comment(linker,"/STACK:102400000,102400000")
#define MEM0(a) (memset((a),0,sizeof(a)))
#define MEMf1(a) (memset((a),-1,sizeof(a)))
#define MEM1(a) (memset((a),1,sizeof(a)))
#define LEN(a) (int)strlen((a))
#define sfd(a) scanf("%d",&(a))
#define sf64d(a) scanf("%I64d",&(a))
#define sflf(a) scanf("%lf",&(a))
#define sfc(a) scanf("%c",&(a))
#define sf2d(a,b) scanf("%d%d",&(a),&(b))
#define sf3d(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sf2lf(a,b) scanf("%lf%lf",&(a),&(b))
#define sf3lf(a,b,c) scanf("%lf%lf%lf",&(a),&(b),&(c))
#define sf264d(a,b) scanf("%I64d%I64d",&(a),&(b))
#define sf364d(a,b,c) scanf("%I64d%I64d%I64d",&(a),&(b),&(c))
#define pfd(a) printf("%d\n",(a))
#define pfc(a) printf("%c",(a));
#define pf64d(a) printf("%I64d\n",(a))
#define pff(a) printf("%f\n",(a))
#define pfs(a) printf("%s\n",(a))
#define pf2d(a,b) printf("%d %d\n",(a),(b))
#define pf2s(a,b) printf("%s %s\n",(a),(b));
#define pf2f(a,b) printf("%f %f\n",(a),(b))
#define pf264d(a,b) printf("%I64d %I64d\n",(a),(b))
#define pfn printf("\n")
#define pfblank printf(" ")
#define LL long long
#define INT_MAX 2147483647
const int MOD = 1000000007;
const int INF = 0x7fffffff;

const int dir4[4][2] = { { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 } };
const int dir8[8][2] = { { -1,0 },{ -1,1 },{ 0,1 },{ 1,1 },{ 1,0 },{ 1,-1 },{ 0,-1 },{ -1,-1 } };

const double eps = 1e-8; const double PI = acos(-1.0);
inline int sign(double x) { return (x>eps) - (x<-eps); }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
/*************************/

int a_count=0, b_count=0;
int apos[100000], bpos[100000];
int main() {
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n, k;
	char in[100000];
	sf2d(n,k);

	int at = 1, bt = 0;

	apos[0] = bpos[0] = 0;

	for (int z = 0; z < n; z++) {
		sfc(in[z]);

		if (in[z] == 'a') {
			a_count++;
			apos[at] = z+1;
			at++;
		}
		else if(in[z]=='b'){
			b_count++;
			bpos[bt] = z+1;
			bt++;
		}
		else {
			z--;
		}
	}
	cout << a_count << endl;
	cout << b_count << endl;

	int ans=0,temp;
	if (k >= Min(a_count, b_count)) {
		cout << n << endl;
	}
	else if (b_count < a_count) {
		for (int i = k; i <= b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
			cout << "i = " << i << "ans = " << ans << endl;
		}
		temp = n - bpos[b_count - k - 1];
		ans = Max(temp, ans);
		cout << ans << endl;
	}
	else if (a_count < b_count) {
		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - apos[a_count - k - 1];
		ans = Max(temp, ans);
		cout << ans << endl;
	}
	else {
		for (int i = k; i <= b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - bpos[b_count - k - 1];
		ans = Max(temp, ans);

		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - apos[a_count - k - 1];
		ans = Max(temp, ans);

		cout << ans << endl;
	}
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
//#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

//#pragma comment(linker,"/STACK:102400000,102400000")
#define MEM0(a) (memset((a),0,sizeof(a)))
#define MEMf1(a) (memset((a),-1,sizeof(a)))
#define MEM1(a) (memset((a),1,sizeof(a)))
#define LEN(a) (int)strlen((a))
#define sfd(a) scanf("%d",&(a))
#define sf64d(a) scanf("%I64d",&(a))
#define sflf(a) scanf("%lf",&(a))
#define sfc(a) scanf("%c",&(a))
#define sf2d(a,b) scanf("%d%d",&(a),&(b))
#define sf3d(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sf2lf(a,b) scanf("%lf%lf",&(a),&(b))
#define sf3lf(a,b,c) scanf("%lf%lf%lf",&(a),&(b),&(c))
#define sf264d(a,b) scanf("%I64d%I64d",&(a),&(b))
#define sf364d(a,b,c) scanf("%I64d%I64d%I64d",&(a),&(b),&(c))
#define pfd(a) printf("%d\n",(a))
#define pfc(a) printf("%c",(a));
#define pf64d(a) printf("%I64d\n",(a))
#define pff(a) printf("%f\n",(a))
#define pfs(a) printf("%s\n",(a))
#define pf2d(a,b) printf("%d %d\n",(a),(b))
#define pf2s(a,b) printf("%s %s\n",(a),(b));
#define pf2f(a,b) printf("%f %f\n",(a),(b))
#define pf264d(a,b) printf("%I64d %I64d\n",(a),(b))
#define pfn printf("\n")
#define pfblank printf(" ")
#define LL long long
#define INT_MAX 2147483647
const int MOD = 1000000007;
const int INF = 0x7fffffff;

const int dir4[4][2] = { { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 } };
const int dir8[8][2] = { { -1,0 },{ -1,1 },{ 0,1 },{ 1,1 },{ 1,0 },{ 1,-1 },{ 0,-1 },{ -1,-1 } };

const double eps = 1e-8; const double PI = acos(-1.0);
inline int sign(double x) { return (x>eps) - (x<-eps); }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
/*************************/

int a_count=0, b_count=0;
int apos[100000], bpos[100000];
int main() {
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n, k;
	char in[100000];
	sf2d(n, k);
	int at = 1, bt = 0;

	apos[0] = bpos[0] = 0;

	for (int z = 0; z < n; z++) {
		sfc(in[z]);
		if (in[z] == 'a') {
			a_count++;
			apos[at] = z+1;
			at++;
		}
		else {
			b_count++;
			bpos[bt] = z+1;
			bt++;
		}
	}
	int ans=0,temp;
	if (k >= Min(a_count, b_count)) {
		cout << n << endl;
	}
	else if (b_count < a_count) {
		for (int i = k; i < b_count-1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}
		cout << ans << endl;
	}
	else if (a_count < b_count) {
		for (int i = k; i < a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		cout << ans << endl;
	}
	else {
		for (int i = k; i < b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}

		for (int i = k; i < a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		cout << ans << endl;
	}
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
//#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

//#pragma comment(linker,"/STACK:102400000,102400000")
#define MEM0(a) (memset((a),0,sizeof(a)))
#define MEMf1(a) (memset((a),-1,sizeof(a)))
#define MEM1(a) (memset((a),1,sizeof(a)))
#define LEN(a) (int)strlen((a))
#define sfd(a) scanf("%d",&(a))
#define sf64d(a) scanf("%I64d",&(a))
#define sflf(a) scanf("%lf",&(a))
#define sfc(a) scanf("%c",&(a))
#define sf2d(a,b) scanf("%d%d",&(a),&(b))
#define sf3d(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sf2lf(a,b) scanf("%lf%lf",&(a),&(b))
#define sf3lf(a,b,c) scanf("%lf%lf%lf",&(a),&(b),&(c))
#define sf264d(a,b) scanf("%I64d%I64d",&(a),&(b))
#define sf364d(a,b,c) scanf("%I64d%I64d%I64d",&(a),&(b),&(c))
#define pfd(a) printf("%d\n",(a))
#define pfc(a) printf("%c",(a));
#define pf64d(a) printf("%I64d\n",(a))
#define pff(a) printf("%f\n",(a))
#define pfs(a) printf("%s\n",(a))
#define pf2d(a,b) printf("%d %d\n",(a),(b))
#define pf2s(a,b) printf("%s %s\n",(a),(b));
#define pf2f(a,b) printf("%f %f\n",(a),(b))
#define pf264d(a,b) printf("%I64d %I64d\n",(a),(b))
#define pfn printf("\n")
#define pfblank printf(" ")
#define LL long long
#define INT_MAX 2147483647
const int MOD = 1000000007;
const int INF = 0x7fffffff;

const int dir4[4][2] = { { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 } };
const int dir8[8][2] = { { -1,0 },{ -1,1 },{ 0,1 },{ 1,1 },{ 1,0 },{ 1,-1 },{ 0,-1 },{ -1,-1 } };

const double eps = 1e-8; const double PI = acos(-1.0);
inline int sign(double x) { return (x>eps) - (x<-eps); }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
/*************************/

int a_count=0, b_count=0;
int apos[100000], bpos[100000];
int main() {
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n, k;
	char in[100000];
	sf2d(n,k);

	int at = 1, bt = 0;

	apos[0] = bpos[0] = 0;

	for (int z = 0; z < n; z++) {
		sfc(in[z]);

		if (in[z] == 'a') {
			a_count++;
			apos[at] = z+1;
			at++;
		}
		else if(in[z]=='b'){
			b_count++;
			bpos[bt] = z+1;
			bt++;
		}
		else {
			z--;
		}
	}
	int ans=0,temp;
	if (k >= Min(a_count, b_count)) {
		cout << n << endl;
	}
	else if (b_count < a_count) {
		for (int i = k; i <= b_count-1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}
		cout << ans << endl;
	}
	else if (a_count < b_count) {
		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		cout << ans << endl;
	}
	else {
		for (int i = k; i <= b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}

		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		cout << ans << endl;
	}
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
//#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

//#pragma comment(linker,"/STACK:102400000,102400000")
#define MEM0(a) (memset((a),0,sizeof(a)))
#define MEMf1(a) (memset((a),-1,sizeof(a)))
#define MEM1(a) (memset((a),1,sizeof(a)))
#define LEN(a) (int)strlen((a))
#define sfd(a) scanf("%d",&(a))
#define sf64d(a) scanf("%I64d",&(a))
#define sflf(a) scanf("%lf",&(a))
#define sfc(a) scanf("%c",&(a))
#define sf2d(a,b) scanf("%d%d",&(a),&(b))
#define sf3d(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sf2lf(a,b) scanf("%lf%lf",&(a),&(b))
#define sf3lf(a,b,c) scanf("%lf%lf%lf",&(a),&(b),&(c))
#define sf264d(a,b) scanf("%I64d%I64d",&(a),&(b))
#define sf364d(a,b,c) scanf("%I64d%I64d%I64d",&(a),&(b),&(c))
#define pfd(a) printf("%d\n",(a))
#define pfc(a) printf("%c",(a));
#define pf64d(a) printf("%I64d\n",(a))
#define pff(a) printf("%f\n",(a))
#define pfs(a) printf("%s\n",(a))
#define pf2d(a,b) printf("%d %d\n",(a),(b))
#define pf2s(a,b) printf("%s %s\n",(a),(b));
#define pf2f(a,b) printf("%f %f\n",(a),(b))
#define pf264d(a,b) printf("%I64d %I64d\n",(a),(b))
#define pfn printf("\n")
#define pfblank printf(" ")
#define LL long long
#define INT_MAX 2147483647
const int MOD = 1000000007;
const int INF = 0x7fffffff;

const int dir4[4][2] = { { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 } };
const int dir8[8][2] = { { -1,0 },{ -1,1 },{ 0,1 },{ 1,1 },{ 1,0 },{ 1,-1 },{ 0,-1 },{ -1,-1 } };

const double eps = 1e-8; const double PI = acos(-1.0);
inline int sign(double x) { return (x>eps) - (x<-eps); }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
/*************************/

int a_count=0, b_count=0;
int apos[100000], bpos[100000];
int main() {
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n, k;
	char in[100000];
	sf2d(n,k);

	int at = 1, bt = 1;

	apos[0] = bpos[0] = 0;

	for (int z = 0; z < n; z++) {
		sfc(in[z]);

		if (in[z] == 'a') {
			a_count++;
			apos[at] = z+1;
			at++;
		}
		else if(in[z]=='b'){
			b_count++;
			bpos[bt] = z+1;
			bt++;
		}
		else {
			z--;
		}
	}

	int ans=0,temp;
	if (k >= Min(a_count, b_count)) {
		cout << n << endl;
	}
	else if (b_count < a_count) {
		for (int i = k; i <= b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - bpos[b_count - k];
		ans = Max(temp, ans);
		cout << ans << endl;
	}
	else if (a_count < b_count) {
		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - apos[a_count - k];
		ans = Max(temp, ans);
		cout << ans << endl;
	}
	else {
		for (int i = k; i <= b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - bpos[b_count - k];
		ans = Max(temp, ans);

		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - apos[a_count - k];
		ans = Max(temp, ans);

		cout << ans << endl;
	}
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
//#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

//#pragma comment(linker,"/STACK:102400000,102400000")
#define MEM0(a) (memset((a),0,sizeof(a)))
#define MEMf1(a) (memset((a),-1,sizeof(a)))
#define MEM1(a) (memset((a),1,sizeof(a)))
#define LEN(a) (int)strlen((a))
#define sfd(a) scanf("%d",&(a))
#define sf64d(a) scanf("%I64d",&(a))
#define sflf(a) scanf("%lf",&(a))
#define sfc(a) scanf("%c",&(a))
#define sf2d(a,b) scanf("%d%d",&(a),&(b))
#define sf3d(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sf2lf(a,b) scanf("%lf%lf",&(a),&(b))
#define sf3lf(a,b,c) scanf("%lf%lf%lf",&(a),&(b),&(c))
#define sf264d(a,b) scanf("%I64d%I64d",&(a),&(b))
#define sf364d(a,b,c) scanf("%I64d%I64d%I64d",&(a),&(b),&(c))
#define pfd(a) printf("%d\n",(a))
#define pfc(a) printf("%c",(a));
#define pf64d(a) printf("%I64d\n",(a))
#define pff(a) printf("%f\n",(a))
#define pfs(a) printf("%s\n",(a))
#define pf2d(a,b) printf("%d %d\n",(a),(b))
#define pf2s(a,b) printf("%s %s\n",(a),(b));
#define pf2f(a,b) printf("%f %f\n",(a),(b))
#define pf264d(a,b) printf("%I64d %I64d\n",(a),(b))
#define pfn printf("\n")
#define pfblank printf(" ")
#define LL long long
#define INT_MAX 2147483647
const int MOD = 1000000007;
const int INF = 0x7fffffff;

const int dir4[4][2] = { { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 } };
const int dir8[8][2] = { { -1,0 },{ -1,1 },{ 0,1 },{ 1,1 },{ 1,0 },{ 1,-1 },{ 0,-1 },{ -1,-1 } };

const double eps = 1e-8; const double PI = acos(-1.0);
inline int sign(double x) { return (x>eps) - (x<-eps); }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
/*************************/

int a_count=0, b_count=0;
int apos[100000], bpos[100000];
int main() {
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n, k;
	char in[100000];
	sf2d(n,k);

	int at = 1, bt = 0;

	apos[0] = bpos[0] = 0;

	for (int z = 0; z < n; z++) {
		sfc(in[z]);

		if (in[z] == 'a') {
			a_count++;
			apos[at] = z+1;
			at++;
		}
		else if(in[z]=='b'){
			b_count++;
			bpos[bt] = z+1;
			bt++;
		}
		else {
			z--;
		}
	}
	int ans=0,temp;
	if (k >= Min(a_count, b_count)) {
		cout << n << endl;
	}
	else if (b_count < a_count) {
		for (int i = k; i <= b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - bpos[b_count - k - 1];
		ans = Max(temp, ans);
		cout << ans << endl;
	}
	else if (a_count < b_count) {
		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - apos[a_count - k - 1];
		ans = Max(temp, ans);
		cout << ans << endl;
	}
	else {
		for (int i = k; i <= b_count - 1; i++) {
			temp = bpos[i + 1] - bpos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - bpos[b_count - k - 1];
		ans = Max(temp, ans);

		for (int i = k; i <= a_count - 1; i++) {
			temp = apos[i + 1] - apos[i - k] - 1;
			ans = Max(temp, ans);
		}
		temp = n - apos[a_count - k - 1];
		ans = Max(temp, ans);

		cout << ans << endl;
	}
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
					ans++;
				if (a[i] == 'b')
					bcount++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
					ans++;
				if (a[i] == 'a')
					acount++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount >= k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				ans++;
				if (a[i] == 'b')
					bcount++;
			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount >= k) {
				if (a[j++] == 'a' && k != 0)
					bcount--;
			}
			else {
				ans++;
				if (a[i] == 'a')
					acount++;
			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {
					if (a[j++] == 'b')
						bcount--;
				}
				else
				if (bcount <= k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount > k){
					if (a[j++] == 'a')
						acount--;
				}
				else
				if (acount <= k)
					ans++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount == k) {}
				else
				if (bcount < k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount >= k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount == k){}
				else
				if (acount < k)
					ans++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
long int acount = 0, bcount = 0, k, n, cnt = 0; long int ans = 0;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (long int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {
					if (a[j++] == 'b')
						bcount--;
				}
				else
				if (bcount <= k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount > k){
					if (a[j++] == 'a')
						acount--;
				}
				else
				if (acount <= k)
					ans++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				ans++;
				if (a[i] == 'b')
					bcount++;
			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					bcount--;
			}
			else {
				ans++;
				if (a[i] == 'a')
					acount++;
			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount >= k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				ans++;
				if (a[i] == 'b')
					bcount++;
			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount >= k && k != 0) {
				if (a[j++] == 'a')
					bcount--;
			}
			else {
				ans++;
				if (a[i] == 'a')
					acount++;
			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
long int acount = 0, bcount = 0, k, n, cnt = 0; long int ans = 0;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (long int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {
					if (a[j++] == 'b')
						bcount--;
				}
				else
				if (bcount <= k)
					ans++;

			}
		}
	}
	else if (bcount > acount) {
		acount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount > k){
					if (a[j++] == 'a')
						acount--;
				}
				else
				if (acount <= k)
					ans++;

			}
		}
	}
	else {
		int ans1 = 0, ans2 = 0;
		bcount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {
					if (a[j++] == 'b')
						bcount--;
				}
				else
					if (bcount <= k)
						ans1++;

			}
		}
		acount = 0;
		j = 0;
		for (long int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if (acount > k) {
					if (a[j++] == 'a')
						acount--;
				}
				else
					if (acount <= k)
						ans2++;

			}
		}
		if (ans1 > ans2)
			ans = ans1;
		else
			ans = ans2;
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
long int acount = 0, bcount = 0, k, n, cnt = 0; long int ans = 0;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
		int ans1 = 0, ans2 = 0;
		bcount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {
					if (a[j++] == 'b')
						bcount--;
				}
				else
					if (bcount <= k)
						ans1++;

			}
		}
		acount = 0;
		j = 0;
		for (long int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if (acount > k) {
					if (a[j++] == 'a')
						acount--;
				}
				else
					if (acount <= k)
						ans2++;

			}
		}
		if (ans1 > ans2)
			ans = ans1;
		else
			ans = ans2;
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {}
				else
				if (bcount <= k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount >= k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount > k){}
				else
				if (acount <= k)
					ans++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount >= k && k != 0) {
				if (a[j++] == 'b' && bcount > k)
					bcount--;
			}
			else {
				if (bcount <= k)
					ans++;
				if (a[i] == 'b')
					bcount++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount >= k && k != 0) {
				if (a[j++] == 'a' && acount > k)
					acount--;
			}
			else {
				if (acount <= k)
					ans++;
				if (a[i] == 'a')
					acount++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
long int acount = 0, bcount = 0, k, n, cnt = 0; long int ans = 0;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	int j = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 'a') {
			acount++;
		}
		else {
			bcount++;
		}
		if (acount < k || bcount < k) {
			ans++;
		}
		else {
			if (a[j++] == 'a')
				acount--;
			else
				bcount--;
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
					continue;
				}
				if (bcount <= k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount >= k && k != 0) {
				if (a[j++] == 'a' && acount > k)
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
					continue;
				}
				if (acount <= k)
					ans++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
long int acount = 0, bcount = 0, k, n, cnt = 0; long int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (long int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (long int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {
					if (a[j++] == 'b')
						bcount--;
				}
				else
				if (bcount <= k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (long int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount > k){
					if (a[j++] == 'a')
						acount--;
				}
				else
				if (acount <= k)
					ans++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {}
				else
				if (bcount <= k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount > k){}
				else
				if (acount <= k)
					ans++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount == k) {}
				else
				if (bcount < k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount >= k && k != 0) {
				if (a[j++] == 'a' && acount > k)
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount == k){}
				else
				if (acount < k)
					ans++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {}
				else
				if (bcount <= k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount >= k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount > k){}
				else
				if (acount <= k)
					ans++;

			}
		}
	}

	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;
	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b')
					bcount++;
				if (bcount <= k)
					ans++;
			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a')
					acount++;
				if(acount <= k)
					ans++;
			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
long int acount = 0, bcount = 0, k, n, cnt = 0; long int ans = 0;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (long int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (long int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {
					if (a[j++] == 'b')
						bcount--;
				}
				else
				if (bcount <= k)
					ans++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (long int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount > k){
					if (a[j++] == 'a')
						acount--;
				}
				else
				if (acount <= k)
					ans++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n,cnt = 0;
char a[100000] = { 0 };
void recursion(int x, int j){
	acount = bcount = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 'a') {
			if (bcount != 0)
				bcount = 0;
			acount++;
			if (acount > cnt)
				cnt = acount;
		}
		else {
			if (acount != 0)
				acount = 0;
			bcount++;
			if (bcount > cnt)
				cnt = bcount;
		}
	}

	for (int i = x; i < n; i++) {
		if (j < k) {
			if (a[i] == 'a')
				a[i] = 'b';
			else
				a[i] = 'a';

			recursion(i + 1, j + 1);

			if (a[i] == 'a')
				a[i] = 'b';
			else
				a[i] = 'a';

		}else
			break;
	}
}

int main()
{
	cin >> n >> k;
	cin >> a;
	recursion(0, 0);
	cout << cnt;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				//if (a[i] == 'b')
					//bcount++;
				if (bcount <= k)
					ans++;
			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				//if (a[i] == 'a')
					//acount++;
				if(acount <= k)
					ans++;
			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b')
					bcount++;
				if (bcount <= k)
					ans++;
			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a')
					acount++;
				if(acount <= k)
					ans++;
			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (bcount <= k)
					ans++;
				if (a[i] == 'b')
					bcount++;

			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (acount <= k)
					ans++;
				if (a[i] == 'a')
					acount++;

			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
long int acount = 0, bcount = 0, k, n, cnt = 0; long int ans = 0;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (long int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {
					if (a[j++] == 'b')
						bcount--;
				}
				else
				if (bcount <= k)
					ans++;

			}
		}
	}
	else if (bcount > acount) {
		acount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if(acount > k){
					if (a[j++] == 'a')
						acount--;
				}
				else
				if (acount <= k)
					ans++;

			}
		}
	}
	else {
		int ans1 = 0, ans2 = 0;
		bcount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b') {
					bcount++;
				}
				if (bcount > k) {
					if (a[j++] == 'b')
						bcount--;
				}
				else
					if (bcount <= k)
						ans1++;

			}
		}
		acount = 0;
		long int j = 0;
		for (long int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a') {
					acount++;
				}
				if (acount > k) {
					if (a[j++] == 'a')
						acount--;
				}
				else
					if (acount <= k)
						ans2++;

			}
		}
		if (ans1 > ans2)
			ans = ans1;
		else
			ans = ans2;
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
long int acount = 0, bcount = 0, k, n, cnt = 0; long int ans = 0;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	int j = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 'a') {
			acount++;
		}
		else {
			bcount++;
		}
		if (acount <= k || bcount <= k) {
			ans++;
		}
		else {
			if (a[j++] == 'a')
				acount--;
			else
				bcount--;
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount >= k) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				ans++;
				if (a[i] == 'b')
					bcount++;
			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount >= k) {
				if (a[j++] == 'a')
					bcount--;
			}
			else {
				ans++;
				if (a[i] == 'a')
					acount++;
			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b')
					bcount++;
				if (bcount <= k)
					ans++;
			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					bcount--;
			}
			else {
				if (a[i] == 'a')
					acount++;
				if(acount <= k)
					ans++;
			}
		}
	}
	cout << ans;
	return 0;
}


#include <stdio.h>
#include <iostream>

using namespace std;
int acount = 0, bcount = 0, k, n, cnt = 0; int ans;
char a[100000] = { 0 };
int main()
{
	cin >> n >> k;
	cin >> a;
	for (int i = 0; i < n; i++)
		if (a[i] == 'a')
			acount++;
		else
			bcount++;

	if (acount > bcount) {
		bcount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (bcount > k && k != 0) {
				if (a[j++] == 'b')
					bcount--;
			}
			else {
				if (a[i] == 'b')
					bcount++;
					ans++;
			}
		}
	}
	else{
		acount = 0;
		int j = 0;
		for (int i = 0; i < n; i++) {
			if (acount > k && k != 0) {
				if (a[j++] == 'a')
					acount--;
			}
			else {
				if (a[i] == 'a')
					acount++;
					ans++;
			}
		}
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i, j, high, a[200000], maxi = -1, mid, temp = 0;
string str, p, v;
bool flag = true;

long long int cnt(string str, long long int low, long long int high, char x)
{
	long long int c=0;

	for (long long int i = low; i <= high; i++)
	{
		if (str[i] == x)
		{
			c++;
		}
	}

	return c;
}

long long int findLeftmark(string a, long long int low, long long int high, long long int pin)
{
	long long int  mid,res=-1,idx=100005;

	if (low <= high)
	{
		mid = (low + high) / 2;

		if (mid == 0 )
		{
			if (a[mid] == a[pin])
			{
				return mid;
			}
			else
			{
				return idx;
			}

		}

		else if (a[mid] == a[pin])
		{
			idx = min(idx, mid);
			return findLeftmark(a, low, mid - 1, pin);
		}
		else
		{
			idx = min(idx, mid);
			return findLeftmark(a, low, mid - 1, pin);
		}
	}
}

int main() {

	cin >> n >> k;
	cin >> str;

	if (n == 1)
	{
		cout << n;
		return 0;
	}

	for (j = n - 1; j > 0; j--)
	{
		long long int c = findLeftmark(str, 0, j - 1, j);

		if (str[j] == 'a')
		{
			if (cnt(str, c, j, 'b') <= k)
			{
				maxi = max(maxi, j - c + 1);
			}
		}
		else if (str[j] == 'b')
		{
			if (cnt(str, c, j, 'a') <= k)
			{
				maxi = max(maxi, j - c + 1);
			}
		}
	}

	cout << maxi;

	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i,j, high, mid;
string str;
bool flag;

bool canSatisfy(int mid) {
    bool flag = false;
    int a = 0, b = 0;
    for (int i = 0; i < mid; ++i) {
        if (s[i] == 'a') a++;
        else b++;
    }
    if (min(a, b) <= k)
        flag = true;
    for (int i = 1; i < n - mid + 1; ++i) {
        if (s[i - 1] == 'a') a--;
        else b--;
        if (s[i + mid - 1] == 'a') a++;
        else b++;
        if (min(a, b) <= k)
            flag = true;
    }
    return flag;
}

int main() {

	low = 1;
	high = n +1;

	while (low+1 != high)
	{
		mid = (low + high) / 2;

		if (canSatisfy(mid))
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}

	cout << low;

	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i, high, a[200000], mid;
string str;
bool flag = true;

bool canSatisfy(long long int mid)
{

	bool flag = false;
	long long int a = 0, b = 0;
	for (long long int i = 0; i < mid; i++)
	{
		if (str[i] == 'a') a++;
		else b++;
	}

	flag = min(a, b) <= k;

	for (int i = 1; i < n - mid + 1; i++) {

		if (str[i - 1] == 'a') a--;
		else b--;

		if (str[i + mid - 1] == 'a') a++;
		else b++;

		flag = min(a, b) <= k;
	}

	return flag;
}

int main() {

	cin >> n >> k;
	cin >> str;

	if (n == 1)
	{
		cout << n;
		return 0;
	}

	low = 1;
	high = n + 1;

	while (low+1 != high)
	{
		mid = (low + high) / 2;

		if (canSatisfy(mid))
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}

	cout << low;

	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i, j, high, a[200000], maxi = -1, mid, temp = 0;
string str, p, v;
bool flag = true;

long long int cnt(string str, long long int low, long long int high, char x)
{
	long long int c = 0;

	for (long long int i = low; i <= high; i++)
	{
		if (str[i] == x)
		{
			c++;
		}
	}

	return c;
}

long long int  res = -1, idx = 100005;

long long int findLeftmark(string a, long long int low, long long int high, long long int pin)
{
    long long int  mid;

	if (low <= high)
	{
		mid = (low + high) / 2;

		if (mid == 0)
		{
			if (a[mid] == a[pin])
			{
				return mid;
			}
			else
			{
				return idx;
			}

		}

		else if (a[mid] == a[pin])
		{
			idx = min(idx, mid);
			return findLeftmark(a, low, mid - 1, pin);
		}
		else
		{
			idx = min(idx, mid);
			return findLeftmark(a, low, mid - 1, pin);
		}
	}
}

int main() {

	cin >> n >> k;
	cin >> str;

	if (n == 1)
	{
		cout << n;
		return 0;
	}

	for (j = n - 1; j > 0; j--)
	{
		long long int c = findLeftmark(str, 0, j - 1, j);

		if (str[j] == 'a')
		{
			if (cnt(str, c, j, 'b') <= k)
			{
				maxi = max(maxi, j - c + 1);
			}
		}
		else if (str[j] == 'b')
		{
			if (cnt(str, c, j, 'a') <= k)
			{
				maxi = max(maxi, j - c + 1);
			}
		}
	}

	cout << maxi;

	return 0;
}


#include<iostream>
#include<string>

using namespace std;

int n,k,i,j,c,bad,ans;
string s;

int main() {

    for( c = 0; c < 2; ++c)
	{
		 bad = 0;

		for(j = 0,  i = 0; j < n; ++j)
		{
			if(s[j] - 'a' != c) ++bad;

			if(bad > k)
			{

				while(i <= j && s[i] - 'a' == c) ++i;

				++i;
				--bad;
			}

				 ans = max(ans, j - i + 1);
		}

	}

	cout << ans;

    return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i, j, high, a[200000], maxi = -1, mid, temp = 0;
string str, p, v;
bool flag = true;

long long int cnt(string str, long long int low, long long int high, char x)
{
	long long int c = 0;

	for (long long int i = low; i <= high; i++)
	{
		if (str[i] == x)
		{
			c++;
		}
	}

	return c;
}

long long int  mid, res = -1, idx = 100005;

long long int findLeftmark(string a, long long int low, long long int high, long long int pin)
{

	if (low <= high)
	{
		mid = (low + high) / 2;

		if (mid == 0)
		{
			if (a[mid] == a[pin])
			{
				return mid;
			}
			else
			{
				return idx;
			}

		}

		else if (a[mid] == a[pin])
		{
			idx = min(idx, mid);
			return findLeftmark(a, low, mid - 1, pin);
		}
		else
		{
			idx = min(idx, mid);
			return findLeftmark(a, low, mid - 1, pin);
		}
	}
}

int main() {

	cin >> n >> k;
	cin >> str;

	if (n == 1)
	{
		cout << n;
		return 0;
	}

	for (j = n - 1; j > 0; j--)
	{
		long long int c = findLeftmark(str, 0, j - 1, j);

		if (str[j] == 'a')
		{
			if (cnt(str, c, j, 'b') <= k)
			{
				maxi = max(maxi, j - c + 1);
			}
		}
		else if (str[j] == 'b')
		{
			if (cnt(str, c, j, 'a') <= k)
			{
				maxi = max(maxi, j - c + 1);
			}
		}
	}

	cout << maxi;

	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i,j, high, mid;
string str;
bool flag;

bool canSatisfy(int mid) {
    bool flag = false;
    int a = 0, b = 0;
    for (int i = 0; i < mid; ++i) {
        if (str[i] == 'a') a++;
        else b++;
    }
    if (min(a, b) <= k)
        flag = true;
    for (int i = 1; i < n - mid + 1; ++i) {
        if (str[i - 1] == 'a') a--;
        else b--;
        if (str[i + mid - 1] == 'a') a++;
        else b++;
        if (min(a, b) <= k)
            flag = true;
    }
    return flag;
}

int main() {

	low = 1;
	high = n +1;

	while (low+1 != high)
	{
		mid = (low + high) / 2;

		if (canSatisfy(mid))
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}

	cout << low;

	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i,j, high, mid;
string str;

bool canSatisfy(long long int m) {
    bool fl = false;
    long long int as = 0, bs = 0;
    for (long long int i = 0; i < m; ++i) {
        if (str[i] == 'a') as++;
        else bs++;
    }
    if (min(as, bs) <= k)
        fl = true;
    for (long long int i = 1; i < n - m + 1; ++i) {
        if (str[i - 1] == 'a') as--;
        else bs--;
        if (str[i + m - 1] == 'a') as++;
        else bs++;
        if (min(as, bs) <= k)
            fl = true;
    }
    return fl;
}

int main() {

	low = 1;
	high = n +1;

	while (low+1 != high)
	{
		mid = (low + high) / 2;

		if (canSatisfy(mid))
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}

	cout << low;

	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i, high, mid;
string str;
bool flag = true;

bool canSatisfy(long long int mid)
{

	bool flag = false;
	long long int a = 0, b = 0;
	for (long long int i = 0; i < mid; i++)
	{
		if (str[i] == 'a') a++;
		else b++;
	}

	flag = min(a, b) <= k;

	a = b = 0;

	for (long long int i = mid; i < n; i++)
	{
		if (str[i] == 'a') a++;
		else b++;
		flag = min(a, b) <= k;
	}

	return flag;
}

int main() {

	cin >> n >> k;
	cin >> str;

	if (n == 1)
	{
		cout << n;
		return 0;
	}

	low = 1;
	high = n + 1;

	while (low+1 != high)
	{
		mid = (low + high) / 2;

		if (canSatisfy(mid))
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}

	cout << low;

	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

int n, k;
string s;

bool solve(int m) {
    bool fl = false;
    int as = 0, bs = 0;
    for (int i = 0; i < m; ++i) {
        if (s[i] == 'a') as++;
        else bs++;
    }
    if (min(as, bs) <= k)
        fl = true;
    for (int i = 1; i < n - m + 1; ++i) {
        if (s[i - 1] == 'a') as--;
        else bs--;
        if (s[i + m - 1] == 'a') as++;
        else bs++;
        if (min(as, bs) <= k)
            fl = true;
    }
    return fl;
}

int main() {
    cin >> n >> k >> s;
    int left = 1, right = n + 1;
    while (left + 1 != right) {
        int middle = (left + right) / 2;
        if (solve(middle))
            left = middle;
        else
            right = middle;
    }
    cout << left;
    return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i, high, a[200000], mid;
string str;
bool flag = true;

bool canSatisfy(long long int mid)
{

	bool flag = false;
	long long int a = 0, b = 0;
	for (long long int i = 0; i < mid; i++)
	{
		if (str[i] == 'a') a++;
		else b++;
	}

	flag = min(a, b) <= k;

	for (int i = 1; i < n - mid + 1; ++i) {

		if (str[i - 1] == 'a') a--;
		else b--;

		if (str[i + mid - 1] == 'a') a++;
		else b++;

		flag = min(a, b) <= k;
	}

	return flag;
}

int main() {

	cin >> n >> k;
	cin >> str;

	if (n == 1)
	{
		cout << n;
		return 0;
	}

	low = 1;
	high = n + 1;

	while (low+1 != high)
	{
		mid = (low + high) / 2;

		if (canSatisfy(mid))
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i,j, high, a[200000], mid;
string str;
bool flag = true;

bool canSatisfy(long long int mid)
{

	bool flag = false;
	long long int a = 0, b = 0;
	for (long long int i = 0; i < mid; i++)
	{
		if (str[i] == 'a') a++;
		else b++;
	}

	flag = min(a, b) <= k;

	for (int i = 1; i < n - mid + 1; i++) {

		for (long long int j = i-1; j < mid + i-1; j++)
	    {
		    if (str[j] == 'a') a++;
		    else b++;
	    }

		flag = min(a, b) <= k;
		a = 0, b = 0;
	}

	return flag;
}

int main() {

	low = 1;
	high = n +1;

	while (low+1 != high)
	{
		mid = (low + high) / 2;

		if (canSatisfy(mid))
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}

	cout << low;

	return 0;
}


#include<iostream>
#include<string>

using namespace std;

int n,k;
string s;

int main() {

    for(int c = 0; c < 2; ++c)
	{
		int bad = 0;

		for(int j = 0,int  i = 0; j < n; ++j)
		{
			if(s[j] - 'a' != c) ++bad;

			if(bad > k)
			{

				while(i <= j && s[i] - 'a' == c) ++i;

				++i;
				--bad;
			}

				int ans = max(ans, j - i + 1);
		}

	}

	cout << ans;

    return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i,j, high, mid;
string str;

bool canSatisfy(int m) {
    bool fl = false;
    int as = 0, bs = 0;
    for (int i = 0; i < m; ++i) {
        if (s[i] == 'a') as++;
        else bs++;
    }
    if (min(as, bs) <= k)
        fl = true;
    for (int i = 1; i < n - m + 1; ++i) {
        if (s[i - 1] == 'a') as--;
        else bs--;
        if (s[i + m - 1] == 'a') as++;
        else bs++;
        if (min(as, bs) <= k)
            fl = true;
    }
    return fl;
}

int main() {

	low = 1;
	high = n +1;

	while (low+1 != high)
	{
		mid = (low + high) / 2;

		if (canSatisfy(mid))
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}

	cout << low;

	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

long long int n, k, low, i, high, a[200000], mid;
string str;
bool flag = true;

bool canSatisfy(long long int mid)
{

	bool flag = false;
	long long int a = 0, b = 0;
	for (long long int i = 0; i < mid; i++)
	{
		if (str[i] == 'a') a++;
		else b++;
	}

	flag = min(a, b) <= k;

	for (int i = 1; i < n - mid + 1; ++i) {

		if (str[i - 1] == 'a') a--;
		else b--;

		if (str[i + mid - 1] == 'a') a++;
		else b++;

		flag = min(a, b) <= k;
	}

	return flag;
}

int main() {

	cin >> n >> k;
	cin >> str;

	if (n == 1)
	{
		cout << n;
		return 0;
	}

	low = 1;
	high = n + 1;

	while (low+1 != high)
	{
		mid = (low + high) / 2;

		if (canSatisfy(mid))
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
	}

	cout << low;

	return 0;
}


#include<iostream>
#include<string>

using namespace std;

int n,k,i,j,c,bad,ans;
string s;

int main() {

    cin >> n >> k;
    cin >> s;

    for( c = 0; c < 2; ++c)
	{
		 bad = 0;

		for(j = 0,  i = 0; j < n; ++j)
		{
			if(s[j] - 'a' != c) ++bad;

			if(bad > k)
			{

				while(i <= j && s[i] - 'a' == c) ++i;

				++i;
				--bad;
			}

				 ans = max(ans, j - i + 1);
		}

	}

	cout << ans;

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <set>
#include <vector>
#include "fstream"
#include "utility"
#include "iterator"
#include "algorithm"
#include <string>
using namespace std;

int n, k, l, r, count1, ans, ans1, f;
string a;
int main(){
	cin >> n >> k >> a;
	while (r<n&&l<=r){
		while (count1<k&&r<n){
			if (a[r] == 'a'){
				count1++;
			}
			r++;
		}
		while (a[r] == 'b'&&r<n){
			r++;
		}
		if (r - l>=ans){
			ans = r - l;
		}
		if (a[l] == 'a'){
			count1--;
		}
		l++;

	}
	r = 0, l = 0, count1 = 0, f = 0;
	while (r<n&&l<=r){
		while (count1<k&&r<n){
			if (a[r] == 'b'){
				count1++;
			}
			r++;
		}
		while (a[r] == 'a'&&r<n){
			r++;
		}
		if (r - l >= ans1){
			ans1 = r - l;
		}
		if (a[l] == 'b'){
			count1--;
		}
		l++;

	}
	cout << max(ans, ans1);
}


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <set>
#include <vector>
#include "fstream"
#include "utility"
#include "iterator"
#include "algorithm"
#include <string>
using namespace std;

int n, k,l,r,count1,ans,ans1,f;
string a;
int main(){
	cin >> n >> k >> a;
	for (int i = 0; i < n; ++i){
		if (r >= n){
			break;
		}
		while (1){
			if (count1 > k){
				f = 1;
				break;
			}
			if (r >= n){
				break;
			}
			if (a[r] == 'a'){
				count1++;
			}
			r++;
		}
		if (r - l>ans){
			if (f){
				ans = r - l;
				ans--;
				f = 0;
			}
			else
			ans = r - l;
		}
		if (a[l] == 'a'){
			count1--;
		}
		l++;

	}
	r = 0, l = 0, count1 = 0,f=0;
	for (int i = 0; i < n; ++i){
		if (r >= n){
			break;
		}
		while (1){
			if (count1>k){
				f = 1;
				break;
			}
			if (r >= n){
				break;
			}
			if (a[r] == 'b'){
				count1++;
			}
			r++;
		}
		if (r - l>ans1){
			if (f){
				ans1 = r - l;
				ans1--;
				f = 0;
			}
			else
			ans1 = r - l;
		}
		if (a[l] == 'b'){
			count1--;
		}
		l++;

	}

	cout << max(ans, ans1);
}


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <set>
#include <vector>
#include "fstream"
#include "utility"
#include "iterator"
#include "algorithm"
#include <string>
using namespace std;

int n, k, l, r, count1, ans, ans1, f;
string a;
int main(){
	cin >> n >> k >> a;
	for (int i = 0; i < n; ++i){
		if (r >= n){
			break;
		}
		while (1){
			if (count1 > k){
				f = 1;
				break;
			}
			if (r >= n){
				break;
			}
			if (a[r] == 'a'){
				count1++;
			}
			r++;
		}
		if (r - l>=ans){
			if (f){
				ans = r - l;
				ans--;
				f = 0;
			}
			else
				ans = r - l;
		}
		if (a[l] == 'a'){
			count1--;
		}
		l++;

	}
	r = 0, l = 0, count1 = 0, f = 0;
	for (int i = 0; i < n; ++i){
		if (r >= n){
			break;
		}
		while (1){
			if (count1>k){
				f = 1;
				break;
			}
			if (r >= n){
				break;
			}
			if (a[r] == 'b'){
				count1++;
			}
			r++;
		}
		if (r - l>=ans1){
			if (f){
				ans1 = r - l;
				ans1--;
				f = 0;
			}
			else
				ans1 = r - l;
		}
		if (a[l] == 'b'){
			count1--;
		}
		l++;

	}

	cout << max(ans, ans1);
}


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <set>
#include <vector>
#include "fstream"
#include "utility"
#include "iterator"
#include "algorithm"
#include <string>
using namespace std;

int n, k, l, r, count1, ans, ans1, f;
string a;
int main(){
	cin >> n >> k >> a;
	while (r<n&&l<n){
		while (count1<k&&r<n){
			if (a[r] == 'a'){
				count1++;
			}
			r++;
		}
		while (a[r] == 'b'&&r<n){
			r++;
		}
		if (r - l>=ans){
			ans = r - l;
		}
		if (a[l] == 'a'){
			count1--;
		}
		l++;

	}
	r = 0, l = 0, count1 = 0, f = 0;
	while (r<n&&l<n){
		while (count1<k&&r<n){
			if (a[r] == 'b'){
				count1++;
			}
			r++;
		}
		while (a[r] == 'a'&&r<n){
			r++;
		}
		if (r - l >= ans1){
			ans1 = r - l;
		}
		if (a[l] == 'b'){
			count1--;
		}
		l++;

	}
	cout << max(ans, ans1);
}


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <set>
#include <vector>
#include "fstream"
#include "utility"
#include "iterator"
#include "algorithm"
#include <string>
using namespace std;

int n, k,l,r,count1,ans,ans1,f;
string a;
int main(){
	cin >> n >> k >> a;
	for (int i = 0; i < n; ++i){
		if (r >= n){
			break;
		}
		while (1){
			if (count1 > k){
				f = 1;
				break;
			}
			if (r >= n){
				break;
			}
			if (a[r] == 'a'){
				count1++;
			}
			r++;
		}
		if (r - l>ans){
			if (f){
				ans = r - l;
				ans--;
				f = 0;
			}
			else
			ans = r - l;
		}
		l++;
		if (a[l] == 'a'){
			count1--;
		}
	}
	r = 0, l = 0, count1 = 0,f=0;
	for (int i = 0; i < n; ++i){
		if (r >= n){
			break;
		}
		while (1){
			if (count1>k){
				f = 1;
				break;
			}
			if (r >= n){
				break;
			}
			if (a[r] == 'b'){
				count1++;
			}
			r++;
		}
		if (r - l>ans1){
			if (f){
				ans1 = r - l;
				ans1--;
				f = 0;
			}
			else
			ans1 = r - l;
		}
		l++;
		if (a[l] == 'b'){
			count1--;
		}
	}
	cout << max(ans, ans1);
}


//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
#include <set>
#include <map>
#include <sstream>
using namespace std;

typedef  long long LL;
typedef  unsigned long long ULL;
typedef  long double LD;
typedef  pair<int, int> PII;
typedef vector<int> VI;

#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define RFOR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i))
#define For(i,a,b) for(int (i)=(a);i<(b);++(i))
#define FoR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i))
#define MP make_pair
#define MOD 1000000009
#define mod 1000000000
#define INF 1000000000
#define PB push_back
#define x0 sdfhrthrth
#define x1 fdhttrlhn
#define y0 kihrbdb
#define y1 ugvrrtgtrg
#define eps 1e-10
#define X first
#define Y second

struct point
{
	double x, y;

	point()
	{
		x = y = 0;
	}

	point(double xx, double yy)
	{
		x = xx; y = yy;
	}

	point operator + (point p)
	{
		return point(x + p.x, y + p.y);
	}

	point operator - (point p)
	{
		return point(x - p.x, y - p.y);
	}

	point operator * (double a)
	{
		return point(x * a, y * a);
	}

	/*int vectMult(point p)
	{
	LL vm = x * p.y - y * p.x;
	if (vm < -eps) return -1;
	if (vm > eps) return 1;
	return 0;
	}*/

	double operator * (point p)
	{
		return x * p.x + y * p.y;
	}

	double len2()
	{
		return (*this) * (*this);
	}

	double len()
	{
		return sqrt((*this).len2());
	}

	bool operator == (point p)
	{
		return ((*this) - p).len() < eps;
	}
};

int n, k;
char arr[100010];
int anss[100010];

int fnc(char c)
{
	int kk = 0;
	int r = 0;
	while (kk <= k && r < n)
	{
		if (arr[r] != c && kk == k) break;
		if (arr[r] != c) kk++;
		r++;
	}
	int ans = r;
	int l = 0;
	int currk = 0;
	while (r < n)
	{
		if (arr[l] != c) currk++;
		l++;
		while (r < n)
		{
			if (arr[r] != c && currk == 0) break;
			if (arr[r] != c) currk--;
			r++;
		}
		ans = max(ans, r - l);
	}
	return ans;
}

int main()
{
	cout.setf(ios::fixed, ios::floatfield);
	cout.precision(2);

	scanf("%d", &n);
	scanf("%d", &k);
	char c;
	scanf("%c", &c);
	For(i, 0, n)
	{
		scanf("%c", &c);
		arr[i] = c;
	}

	int anss = max(fnc('a'), fnc('b'));
	printf("%d\n", anss);

	return 0;
}


#include <stdio.h>
#include <string.h>
using namespace std; // 'a'=0 'b'=1
char given[1100000];
int f[1100000];
int n, k;
int loc0[1100000];
int loc1[1100000];
int cnt0, cnt1;
int ans;
int max(int a, int b)
{
	return a>b?a:b;
}
int main(void)
{
	int i;
	scanf("%d %d",&n,&k);
	scanf("%s",&given[1]);
	for(i=1 ; i<=n ; i++)
	{
		f[i]=given[i]-'a';
		if(f[i]==0)
		{
			cnt0++;
			loc0[cnt0]=i;
		}
		if(f[i]==1)
		{
			cnt1++;
			loc1[cnt1]=i;
		}
	}
	loc0[0]=0; loc0[cnt0+1]=n+1; loc1[0]=0; loc1[cnt1+1]=n+1;
	for(i=0 ; i<=cnt0-k ; i++)
	{
		ans=max(ans,loc0[i+k+1]-loc0[i]-1);
	}
	for(i=0 ; i<=cnt1-k ; i++)
	{
		ans=max(ans,loc1[i+k+1]-loc1[i]-1);
	}
	printf("%d",ans);
}


#include <stdio.h>
#include <string.h>
using namespace std; // 'a'=0 'b'=1
char given[1100000];
int f[1100000];
int n, k;
int loc0[1100000];
int loc1[1100000];
int cnt0, cnt1;
int ans;
int max(int a, int b)
{
	return a>b?a:b;
}
int main(void)
{
	int i;
	scanf("%d %d",&n,&k);
	scanf("%s",&given[1]);
	for(i=1 ; i<=n ; i++)
	{
		f[i]=given[i]-'a';
		if(f[i]==0)
		{
			cnt0++;
			loc0[cnt0]=i;
		}
		if(f[i]==1)
		{
			cnt1++;
			loc1[cnt1]=i;
		}
	}
	loc0[0]=0; loc0[cnt0+1]=n+1; loc1[0]=0; loc1[cnt1+1]=n+1;
	if(cnt1<=k || cnt0<=k)
	{
		printf("%d",n);
		return 0;
	}
	for(i=0 ; i<=cnt0-k ; i++)
	{
		ans=max(ans,loc0[i+k+1]-loc0[i]-1);
	}
	for(i=0 ; i<=cnt1-k ; i++)
	{
		ans=max(ans,loc1[i+k+1]-loc1[i]-1);
	}
	printf("%d",ans);
}


#include<iostream>
using namespace std;

//ifstream cin("input.txt");
//ofstream cout("output.txt");

char Data[100010];
int Dy1[100010];
int Dy2[100010];
int sum1[100010];
int sum2[100010];
int ans;
int ma(int a, int b)
{
	if (a < b)return b;
	return a;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int m = 0;
	cin >> Data;
	if (Data[0] == 'b')
	{
		for (int i = 0; i < n; i++)
		{
			if (Data[i] == 'a')Data[i] = 'b';
			else if (Data[i] == 'b')Data[i] = 'a';
		}
	}
	int a = 0, b = 0;
	if (Data[0] == 'a')Dy1[a]++;
	else
		Dy2[b]++;
	for (int i = 1; i < n; i++)
	{
		if (Data[i] == 'a')
		{
			if (Data[i - 1] == 'b')
			{
				Dy1[++a]++;
			}
			else
			{
				Dy1[a]++;
			}
		}
		else
		{
			if (Data[i - 1] == 'a')
			{
				Dy2[++b]++;
			}
			else
			{
				Dy2[b]++;
			}
		}
	}
	sum1[0] = Dy1[0];
	sum2[0] = Dy2[0];
	ans = ma(Dy1[0], Dy2[0]);
	for (int i = 1; i <= a+1; i++)
	{
		sum1[i] = sum1[i - 1] + Dy1[i];
		ans = ma(ans, Dy1[i]);
	}
	for (int i = 1; i <= b+1; i++)
	{
		sum2[i] = sum2[i - 1] + Dy2[i];
		ans = ma(ans, Dy2[i]);
	}
	int s, start=-1;
	for (int i = 1; i <= b; i++)
	{
		if (Dy2[i] <= k)
		{
			start = i;
			s = Dy2[i];
			break;
		}
	}
	if (start != -1)
	{
		ans = ma(ans,Dy1[start - 1] + Dy1[start] + s);
		int q = start;
		for (int i = q + 1; i <= b; i++)
		{
			s += Dy2[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy2[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp2 = 0;
			if (start - 2 >= 0)
				tmp2 = sum1[start - 2];
			int tmp = sum1[i] - tmp2+s;
			if (tmp > ans)
				ans = tmp;
		}
	}

	int ans2 = 0;
	s, start = -1;
	for (int i = 0; i <= a; i++)
	{
		if (Dy1[i] <= k)
		{
			start = i;
			s = Dy1[i];
			break;
		}
	}
	if (start != -1)
	{
		ans2 = ma(ans2, s+Dy2[start+1]);
		int q = start;
		for (int i = q + 1; i <= a; i++)
		{
			s += Dy1[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy1[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp = sum2[i + 1] - sum2[start]+s;
			ans2 = ma(ans2, tmp);
		}
	}
	ans = ma(ans, ans2);
	cout << ans;
	return 0;
}


#include<iostream>
using namespace std;

//ifstream cin("input.txt");
//ofstream cout("output.txt");

char Data[100010];
int Dy1[100010];
int Dy2[100010];
int sum1[100010];
int sum2[100010];
int ans;
int ma(int a, int b)
{
	if (a < b)return b;
	return a;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int m = 0;
	cin >> Data;
	if (Data[0] == 'b')
	{
		for (int i = 0; i < n; i++)
		{
			if (Data[i] == 'a')Data[i] = 'b';
			else if (Data[i] == 'b')Data[i] = 'a';
		}
	}
	int a = 0, b = 0;
	if (Data[0] == 'a')Dy1[a]++;
	else
		Dy2[b]++;
	for (int i = 1; i < n; i++)
	{
		if (Data[i] == 'a')
		{
			if (Data[i - 1] == 'b')
			{
				Dy1[++a]++;
			}
			else
			{
				Dy1[a]++;
			}
		}
		else
		{
			if (Data[i - 1] == 'a')
			{
				Dy2[++b]++;
			}
			else
			{
				Dy2[b]++;
			}
		}
	}
	a++;
	b++;
	sum1[0] = Dy1[0];
	sum2[0] = Dy2[0];
	ans = ma(Dy1[0], Dy2[0]);
	for (int i = 1; i <= a; i++)
	{
		sum1[i] = sum1[i - 1] + Dy1[i];
		ans = ma(ans, Dy1[i]);
	}
	for (int i = 1; i <= b; i++)
	{
		sum2[i] = sum2[i - 1] + Dy2[i];
		ans = ma(ans, Dy2[i]);
	}
	int s, start=-1;
	for (int i = 1; i <= b; i++)
	{
		if (Dy2[i] <= k)
		{
			start = i;
			s = Dy2[i];
			break;
		}
	}
	if (start != -1)
	{
		ans = ma(ans,Dy1[start - 1] + Dy1[start] + s);
		int q = start;
		for (int i = q + 1; i <= b; i++)
		{
			s += Dy2[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy2[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp2 = 0;
			if (start - 2 >= 0)
				tmp2 = sum1[start - 2];
			int tmp = sum1[i] - tmp2+s;
			if (tmp > ans)
				ans = tmp;
		}
	}

	int ans2 = 0;
	s, start = -1;
	for (int i = 0; i <= a; i++)
	{
		if (Dy1[i] <= k)
		{
			start = i;
			s = Dy1[i];
			break;
		}
	}
	if (start != -1)
	{
		ans2 = ma(ans2, s+Dy2[start+1]);
		int q = start;
		for (int i = q + 1; i <= a; i++)
		{
			s += Dy1[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy1[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp = sum2[i + 1] - sum2[start]+s;
			ans2 = ma(ans2, tmp);
		}
	}
	ans = ma(ans, ans2);
	cout << ans;
	return 0;
}


#include<iostream>
using namespace std;

//ifstream cin("input.txt");
//ofstream cout("output.txt");

char Data[100010];
int Dy1[100010];
int Dy2[100010];
int sum1[100010];
int sum2[100010];
int ans;
int ma(int a, int b)
{
	if (a < b)return b;
	return a;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int m = 0;
	cin >> Data;
	if (Data[0] == 'b')
	{
		for (int i = 0; i < n; i++)
		{
			if (Data[i] == 'a')Data[i] = 'b';
			else if (Data[i] == 'b')Data[i] = 'a';
		}
	}
	int a = 0, b = 0;
	if (Data[0] == 'a')Dy1[a]++;
	else
		Dy2[b]++;
	for (int i = 1; i < n; i++)
	{
		if (Data[i] == 'a')
		{
			if (Data[i - 1] == 'b')
			{
				Dy1[++a]++;
			}
			else
			{
				Dy1[a]++;
			}
		}
		else
		{
			if (Data[i - 1] == 'a')
			{
				Dy2[++b]++;
			}
			else
			{
				Dy2[b]++;
			}
		}
	}
	sum1[0] = Dy1[0];
	sum2[0] = Dy2[0];
	ans = ma(Dy1[0], Dy2[0]);
	for (int i = 1; i <= a; i++)
	{
		sum1[i] = sum1[i - 1] + Dy1[i];
		ans = ma(ans, Dy1[i]);
	}
	for (int i = 1; i <= b; i++)
	{
		sum2[i] = sum2[i - 1] + Dy2[i];
		ans = ma(ans, Dy2[i]);
	}

	int s, start=-1;
	for (int i = 1; i <= b; i++)
	{
		if (Dy2[i] <= k)
		{
			start = i;
			s = Dy2[i];
			break;
		}
	}
	if (start != -1)
	{
		int q = start;
		for (int i = q + 1; i <= b; i++)
		{
			s += Dy2[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy2[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp2 = 0;
			if (start - 2 >= 0)
				tmp2 = sum1[start - 2];
			int tmp = sum1[i] - tmp2+s;
			if (tmp > ans)
				ans = tmp;
		}
	}
	cout << ans;
	return 0;
}


#include<iostream>
using namespace std;

//ifstream cin("input.txt");
//ofstream cout("output.txt");

int n, k;
char Data[100010];
int ma(int a, int b)
{
	if (a < b)return b;
	return a;
}
int process()
{
	int S = 0, E = 0;
	int change = 0;
	int ans = 0;
	while (S != n)
	{
		if (S > E || E >= n)break;
		if (Data[E] == 'a')
			E++;
		else if (Data[E] == 'b')
		{
			if (change == k)
			{
				for (;;)
				{
					if (Data[S] == 'b')
					{
						change--;
						S++;
						break;
					}
					S++;
				}
			}
			change++;
			E++;
		}
		ans = ma(ans, E - S);
	}
	return ans;
}
int main()
{
	cin >> n >> k;
	cin >> Data;

	int ans1 = process();
	for (int i = 0; i < n; i++)
	{
		if (Data[i] == 'a')Data[i] = 'b';
		else if (Data[i] == 'b')Data[i] = 'a';
	}
	int ans2 = process();
	cout << ma(ans1, ans2);
	return 0;
}


#include<iostream>
using namespace std;

//ifstream cin("input.txt");
//ofstream cout("output.txt");

char Data[100010];
int Dy1[100010];
int Dy2[100010];
int sum1[100010];
int sum2[100010];
int ans;
int ma(int a, int b)
{
	if (a < b)return b;
	return a;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int m = 0;
	cin >> Data;
	if (Data[0] == 'b')
	{
		for (int i = 0; i < n; i++)
		{
			if (Data[i] == 'a')Data[i] = 'b';
			else if (Data[i] == 'b')Data[i] = 'a';
		}
	}
	int a = 0, b = 0;
	if (Data[0] == 'a')Dy1[a]++;
	else
		Dy2[b]++;
	for (int i = 1; i < n; i++)
	{
		if (Data[i] == 'a')
		{
			if (Data[i - 1] == 'b')
			{
				Dy1[++a]++;
			}
			else
			{
				Dy1[a]++;
			}
		}
		else
		{
			if (Data[i - 1] == 'a')
			{
				Dy2[++b]++;
			}
			else
			{
				Dy2[b]++;
			}
		}
	}
	sum1[0] = Dy1[0];
	sum2[0] = Dy2[0];
	ans = ma(Dy1[0], Dy2[0]);
	for (int i = 1; i <= a; i++)
	{
		sum1[i] = sum1[i - 1] + Dy1[i];
		ans = ma(ans, Dy1[i]);
	}
	for (int i = 1; i <= b; i++)
	{
		sum2[i] = sum2[i - 1] + Dy2[i];
		ans = ma(ans, Dy2[i]);
	}

	int s, start=-1;
	for (int i = 1; i <= b; i++)
	{
		if (Dy2[i] <= k)
		{
			start = i;
			s = Dy2[i];
			break;
		}
	}
	if (start != -1)
	{
		ans = ma(ans,Dy1[start - 1] + Dy1[start] + s);
		int q = start;
		for (int i = q + 1; i <= b; i++)
		{
			s += Dy2[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy2[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp2 = 0;
			if (start - 2 >= 0)
				tmp2 = sum1[start - 2];
			int tmp = sum1[i] - tmp2+s;
			if (tmp > ans)
				ans = tmp;
		}
	}
	cout << ans;
	return 0;
}


#include<iostream>
using namespace std;

//ifstream cin("input.txt");
//ofstream cout("output.txt");

char Data[100010];
int Dy1[100010];
int Dy2[100010];
int sum1[100010];
int sum2[100010];
int ans;
int ma(int a, int b)
{
	if (a < b)return b;
	return a;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int m = 0;
	cin >> Data;
	if (Data[0] == 'b')
	{
		for (int i = 0; i < n; i++)
		{
			if (Data[i] == 'a')Data[i] = 'b';
			else if (Data[i] == 'b')Data[i] = 'a';
		}
	}
	int a = 0, b = 0;
	if (Data[0] == 'a')Dy1[a]++;
	else
		Dy2[b]++;
	for (int i = 1; i < n; i++)
	{
		if (Data[i] == 'a')
		{
			if (Data[i - 1] == 'b')
			{
				Dy1[++a]++;
			}
			else
			{
				Dy1[a]++;
			}
		}
		else
		{
			if (Data[i - 1] == 'a')
			{
				Dy2[++b]++;
			}
			else
			{
				Dy2[b]++;
			}
		}
	}
	sum1[0] = Dy1[0];
	sum2[0] = Dy2[0];
	ans = ma(Dy1[0], Dy2[0]);
	for (int i = 1; i <= a; i++)
	{
		sum1[i] = sum1[i - 1] + Dy1[i];
		ans = ma(ans, Dy1[i]);
	}
	for (int i = 1; i <= b; i++)
	{
		sum2[i] = sum2[i - 1] + Dy2[i];
		ans = ma(ans, Dy2[i]);
	}

	int s, start=-1;
	for (int i = 1; i <= b; i++)
	{
		if (Dy2[i] <= k)
		{
			start = i;
			s = Dy2[i];
			break;
		}
	}
	if (start != -1)
	{
		ans = ma(ans,Dy1[start - 1] + Dy1[start] + s);
		int q = start;
		for (int i = q + 1; i <= b; i++)
		{
			s += Dy2[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy2[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp2 = 0;
			if (start - 2 >= 0)
				tmp2 = sum1[start - 2];
			int tmp = sum1[i] - tmp2+s;
			if (tmp > ans)
				ans = tmp;
		}
	}

	int ans2 = 0;
	s, start = -1;
	for (int i = 0; i <= a; i++)
	{
		if (Dy1[i] <= k)
		{
			start = i;
			s = Dy1[i];
			break;
		}
	}
	if (start != -1)
	{
		ans2 = ma(ans2, s+Dy2[start+1]);
		int q = start;
		for (int i = q + 1; i <= a; i++)
		{
			s += Dy1[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy1[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp = sum2[i + 1] - sum2[start]+s;
			ans2 = ma(ans2, tmp);
		}
	}
	ans = ma(ans, ans2);
	cout << ans;
	return 0;
}


#include<iostream>
using namespace std;

//ifstream cin("input.txt");
//ofstream cout("output.txt");

char Data[100010];
int Dy1[100010];
int Dy2[100010];
int sum1[100010];
int sum2[100010];
int ans;
int main()
{
	int n, k;
	cin >> n >> k;
	int m = 0;
	cin >> Data;
	if (Data[0] == 'b')
	{
		for (int i = 0; i < n; i++)
		{
			if (Data[i] == 'a')Data[i] = 'b';
			else if (Data[i] == 'b')Data[i] = 'a';
		}
	}
	int a = 0, b = 0;
	if (Data[0] == 'a')Dy1[a]++;
	else
		Dy2[b]++;
	for (int i = 1; i < n; i++)
	{
		if (Data[i] == 'a')
		{
			if (Data[i - 1] == 'b')
			{
				Dy1[++a]++;
			}
			else
			{
				Dy1[a]++;
			}
		}
		else
		{
			if (Data[i - 1] == 'a')
			{
				Dy2[++b]++;
			}
			else
			{
				Dy2[b]++;
			}
		}
	}
	sum1[0] = Dy1[0];
	sum2[0] = Dy2[0];
	for (int i = 1; i <= a; i++)
		sum1[i] = sum1[i - 1] + Dy1[i];
	for (int i = 1; i <= b; i++)
		sum2[i] = sum2[i - 1] + Dy2[i];

	int s, start=-1;
	for (int i = 1; i <= b; i++)
	{
		if (Dy2[i] <= k)
		{
			start = i;
			s = Dy2[i];
			break;
		}
	}
	if (start != -1)
	{
		ans = Dy1[start - 1] + Dy1[start] + s;
		int q = start;
		for (int i = q + 1; i <= b; i++)
		{
			s += Dy2[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy2[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp2 = 0;
			if (start - 2 >= 0)
				tmp2 = sum1[start - 2];
			int tmp = sum1[i] - tmp2+s;
			if (tmp > ans)
				ans = tmp;
		}
	}
	cout << ans;
	return 0;
}


#include<iostream>
using namespace std;

//ifstream cin("input.txt");
//ofstream cout("output.txt");

char Data[100010];
int Dy1[100010];
int Dy2[100010];
int sum1[100010];
int sum2[100010];
int ans;
int ma(int a, int b)
{
	if (a < b)return b;
	return a;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int m = 0;
	cin >> Data;
	if (Data[0] == 'b')
	{
		for (int i = 0; i < n; i++)
		{
			if (Data[i] == 'a')Data[i] = 'b';
			else if (Data[i] == 'b')Data[i] = 'a';
		}
	}
	int a = 0, b = 0;
	if (Data[0] == 'a')Dy1[a]++;
	else
		Dy2[b]++;
	for (int i = 1; i < n; i++)
	{
		if (Data[i] == 'a')
		{
			if (Data[i - 1] == 'b')
			{
				Dy1[++a]++;
			}
			else
			{
				Dy1[a]++;
			}
		}
		else
		{
			if (Data[i - 1] == 'a')
			{
				Dy2[++b]++;
			}
			else
			{
				Dy2[b]++;
			}
		}
	}
	sum1[0] = Dy1[0];
	sum2[0] = Dy2[0];
	ans = ma(Dy1[0], Dy2[0]);
	for (int i = 1; i <= a+1; i++)
	{
		sum1[i] = sum1[i - 1] + Dy1[i];
		ans = ma(ans, Dy1[i]);
	}
	for (int i = 1; i <= b; i++)
	{
		sum2[i] = sum2[i - 1] + Dy2[i];
		ans = ma(ans, Dy2[i]);
	}
	int s, start=-1;
	for (int i = 1; i <= b; i++)
	{
		if (Dy2[i] <= k)
		{
			start = i;
			s = Dy2[i];
			break;
		}
	}
	if (start != -1)
	{
		ans = ma(ans,Dy1[start - 1] + Dy1[start] + s);
		int q = start;
		for (int i = q + 1; i <= b; i++)
		{
			s += Dy2[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy2[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp2 = 0;
			if (start - 2 >= 0)
				tmp2 = sum1[start - 2];
			int tmp = sum1[i] - tmp2+s;
			if (tmp > ans)
				ans = tmp;
		}
	}

	int ans2 = 0;
	s, start = -1;
	for (int i = 0; i <= a; i++)
	{
		if (Dy1[i] <= k)
		{
			start = i;
			s = Dy1[i];
			break;
		}
	}
	if (start != -1)
	{
		ans2 = ma(ans2, s+Dy2[start+1]);
		int q = start;
		for (int i = q + 1; i <= a; i++)
		{
			s += Dy1[i];
			if (s > k)
			{
				for (int j = start; j <= i; j++)
				{
					s -= Dy1[j];
					if (s <= k)
					{
						start = j + 1; break;
					}
				}
			}
			int tmp = sum2[i + 1] - sum2[start]+s;
			ans2 = ma(ans2, tmp);
		}
	}
	ans = ma(ans, ans2);
	cout << ans;
	return 0;
}


#include <cstdio>
using namespace std;

int n, k;
char s[100001];
int wposa[100001], wposai, wposan;
int wposb[100001], wposbi, wposbn;

int main() {
    int i;
    int cmaxa, changesa;
    int cmaxb, changesb;

    scanf("%d %d", &n, &k);
    scanf("%s", s);

    cmaxa = 0; wposai = 0; wposan = 0;
    cmaxb = 0; wposbi = 0; wposbn = 0;
    for (i = 0; i < n; ++i) {
        if (s[i] != 'a') {
            wposa[wposan++] = i;
            if (wposan > k)
                cmaxa = i - 1 - wposa[wposai++];
        }
        if (s[i] != 'b') {
            wposb[wposbn++] = i;
            if (wposbn > k)
                cmaxb = i - 1 - wposb[wposbi++];
        }
        ++cmaxb;
        ++cmaxa;
    }
    if (cmaxa > cmaxb)
        printf("%d\n", cmaxa);
    else
        printf("%d\n", cmaxb);

    return 0;
}