#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <climits>
#include <string>
#include <cctype>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;

// <editor-fold defaultstate="collapsed" desc="Defines">

typedef long long ll;
typedef unsigned long long ull;
typedef map<int, int> mi;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
const double PI = 3.14159265358979;
const double PI2 = 6.28318530717958;
const double PId2 = 1.570796326794895;
#define MP make_pair
#define X first
#define Y second
#define eps 1E-7
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

template<typename T> T sqr(T x)
{
    return x*x;
}

template<typename T> T gcd(T a, T b)
{
    return (b ? gcd(b, a % b) : a);
}

inline ll pw(ll n, int p)
{
    ll ans = 1;
    for (int i = 0; i < p; i++) ans *= n;
    return ans;
}

inline vi ReadVI(int count)
{
    vi arrayname(count);
    for (int i = 0; i < count; i++) cin >> arrayname[i];
    return arrayname;
}

inline vll ReadVlong(int count)
{
    vll arrayname(count);
    for (int i = 0; i < count; i++) cin >> arrayname[i];
    return arrayname;
}

const int MOD = 100000000;
const int MAXVALUE = 10000001;

// </editor-fold >

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    string s;
    bool sp = false;
    getline(cin, s);
    for (int i = 0; i < s.size(); i++) {
        char c = s[i];
        switch (c) {
            case ' ':
                sp = true;
                break;
            case '!':
            case '?':
            case '.':
            case ',':
                cout << s[i], sp = true;
                break;
            default:
                if (sp) cout << ' ', sp = false;
                cout << s[i];
                break;
        }
    }
    return 0;
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
using namespace std;
int main()
{
string x;
getline(cin,x);
for (int i=0;i<x.size();i++){
    if (x[i]==' ' and x[i+1]==' '){
        x.erase(i+1,1);
        i--;
    }
    if (x[i]==' ' and ispunct(x[i+1])){
        x.erase(i,1);
        i--;
    }
}
for (int i=0;i<x.size();i++){
         if (ispunct(x[i]) and x[i+1]!=' '){
             cout<<x[i]<<' ';
         }
         else{
             cout<<x[i];
             }
}
}


#include <cstdio>
#include <ctype.h>
#include <iostream>
#include <cstring>

using namespace std;

char s1[10005],s2[100005];

int main()
{
    cin.getline(s1, 10005);
    int i=0,j=0;

    for (i=0; s1[i]!='\0';)
    {
        if (isalpha(s1[i]))
        {
            while (isalpha(s1[i]))
            {
                s2[j] = s1[i];
                j++;
                i++;
            }
        }
        else if (s1[i]==' ')
        {
            if (s2[j-1]==' ')
            {
                i++;
                continue;
            }
            while (s1[i]==' ')
                i++;

            s2[j] = ' ';
            j++;
        }
        else //punctuation
        {
            if (s2[j-1]==' ')
                j--;
            s2[j++] = s1[i++];
            s2[j++] = ' ';
        }
    }
    s2[j] = '\0';
    puts(s2);
    return 0;
}


#include <cstdio>
#include <ctype.h>
#include <iostream>
#include <cstring>

using namespace std;

char s1[10005],s2[100005];

int main()
{
    cin.getline(s1, 10005);
    int i=0,j=0;

    for (i=0; s1[i]!='\0';)
    {
        if (isalpha(s1[i]))
        {
            while (isalpha(s1[i]))
            {
                s2[j] = s1[i];
                j++;
                i++;
            }
        }
        else if (s1[i]==' ')
        {
            while (s1[i]==' ')
                i++;

            s2[j] = ' ';
            j++;
        }
        else //punctuation
        {
            if (s2[j-1]==' ')
                j--;
            s2[j++] = s1[i++];
            s2[j++] = ' ';
        }
    }
    s2[j] = '\0';
    puts(s2);
    return 0;
}


#include <cstdio>
#include <ctype.h>
#include <iostream>
#include <cstring>

using namespace std;

char s1[10005],s2[100005];

int main()
{
    cin.getline(s1, 10005);
    int i=0,j=0;

    for (i=0; s1[i]!='\0';)
    {
        if (isalpha(s1[i]))
        {
            while (isalpha(s1[i]))
            {
                s2[j] = s1[i];
                j++;
                i++;
            }
        }
        else if (s1[i]==' ')
        {
            if (s2[j-1]==' ')
            {
                i++;
                continue;
            }
            while (s1[i]==' ')
                i++;

            s2[j] = ' ';
            j++;
        }
        else //punctuation
        {
            if (s2[j-1]==' ')
                j--;
            s2[j++] = s1[i++];
        }
    }
    s2[j] = '\0';
    puts(s2);
    return 0;
}


#ifdef MY_SUPER_PUPER_ONLINE_JUDGE
#include <fstream>
using namespace std;
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <iostream>
using namespace std;
#endif
#include <string>

int main()
{
    string str;
    getline(cin, str);
    auto n = str.length();
    for(size_t i=0;i<n;)
    {
        auto j = i;
        while(j < n && isalpha(str[j])) j++;
        cout << str.substr(i, j - i);
        while(j < n && str[j] == ' ') j++;
        // Млин, ну если еще раз сломаете, я со смеху помру :)
        if(j < n && (str[j] == ',' || str[j] == '.' || str[j] == '!' || str[j] == '?'))
        {
            cout << str[j];
            j++;
        }
        while(j < n && str[j] == ' ') j++;
        if(j!=n) cout << ' ';
        i = j;
    }
}


#ifdef MY_SUPER_PUPER_ONLINE_JUDGE
#include <fstream>
using namespace std;
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <iostream>
using namespace std;
#endif
#include <string>

int main()
{
    string str;
    getline(cin, str);
    auto n = str.length();
    for(size_t i=0;i<n;)
    {
        auto j = i;
        while(j < n && isalpha(str[j])) j++;
        cout << str.substr(i, j - i);
        while(j < n && str[j] == ' ') j++;
        if(j < n && str[j] == ',')
        {
            cout << ',';
            j++;
        }
        while(j < n && str[j] == ' ') j++;
        if(j!=n) cout << ' ';
        i = j;
    }
}


#ifdef MY_SUPER_PUPER_ONLINE_JUDGE
#include <fstream>
using namespace std;
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <iostream>
using namespace std;
#endif
#include <string>

int main()
{
    string str;
    getline(cin, str);
    auto n = str.length();
    for(size_t i=0;i<n;)
    {
        auto j = i;
        while(j < n && isalpha(str[j])) j++;
        cout << str.substr(i, j - i);
        while(j < n && str[j] == ' ') j++;
        if(j < n && str[j] == ',')
        {
            cout << ',';
            j++;
        }
        if(j!=n) cout << ' ';
        i = j;
    }
}


#ifdef MY_SUPER_PUPER_ONLINE_JUDGE
#include <fstream>
using namespace std;
ifstream cin("input.txt");
ofstream cout("output.txt");
#else
#include <iostream>
using namespace std;
#endif
#include <string>

int main()
{
    string str;
    getline(cin, str);
    auto n = str.length();
    for(size_t i=0;i<n;)
    {
        auto j = i;
        while(j < n && isalpha(str[j])) j++;
        cout << str.substr(i, j - i);
        while(j < n && str[j] == ' ') j++;
        // Млин, ну если еще раз сломаете, я со смеху помру :)
        if(j < n && (str[j] == ',' || str[j] == '.' || str[j] == '!' || str[j] == '?'))
        {
            cout << ',';
            j++;
        }
        while(j < n && str[j] == ' ') j++;
        if(j!=n) cout << ' ';
        i = j;
    }
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
string s;
getline(cin,s);
for (int i=0;i<s.size();i++){
    if (s[i]==' '&&s[i+1]==' '){
        s.erase(s.begin()+(i+1));
        i--;
        }
    else if (s[i]==','||s[i]=='.'||s[i]=='!'||s[i]=='?'){
        if (s[i-1]==' '){
            s.erase(s.begin()+i-1);
            i-=2;
            }
        else if (s[i-1]!=' ')
            s.insert(s.begin()+(i+1),' ');
    }
}
cout<<s<<endl;
}


/*
ID: keyvank2
TASK: combo
LANG: C++
*/

#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MAXINT ((~0) ^ (1 << 31))
#define MAXLL ((~0) ^ ((ll)1 << 63))
#define INF ((int)2e9)
#define INFL ((ll)9e18)
#define FOR(i,j,k) for(int i = j; i < k; i++)
#define REP(i,j,k) for(int i = j; i >= k; i--)
#define setmax(i) const int maxn = (int) i;
#define setmod(i) const int MOD = (int) i;
#define all(a) a.begin(),a.end()

using namespace std;

//ifstream fin("");
//ofstream fout("");
//#define cin fin
//#define cout fout

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef pair<pii,int> ppi;
typedef pair<pll,ll> ppl;
typedef pair<int,pii> pip;
typedef pair<ll,pll> plp;
typedef pair<pii,pii> ppp;

template<class T> inline T pow2(T a) {return a*a;}
template<class T> inline bool mineq(T& a, T b) { if(a < b) {a=b;return true;} return false;}

//srand (time(NULL));

string str,ans;

bool punc(char a)
{
    return a=='.' || a==',' || a=='?' || a=='!';
}

int main()
{
    getline(cin,str);
    bool f = false;
    FOR(i,0,str.size())
    {
        if(str[i] == ' ') f = true;
        else if(punc(str[i]))
        {
            ans.pb(str[i]);
            f = true;
        }
        else
        {
            if(f) ans.pb(' ');
            ans.pb(str[i]);
            f = false;
        }
    }
    cout << ans << endl;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s , t=" ";
   getline(cin,s) ;
   for(int i = 0 ; i<s.size() ; i++){
     if(s[i] == ' '){
        for(int j=i+1 ; j<s.size() ; j++){
            if(s[i]==s[j]){
                s.erase(j,1);
                j--;
            }
            else if(s[j]==','){s.erase(i,1);s.insert(i+1,t,0,1) ; break ;}
            else
                break ;
        }
    }
}
cout<<s;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s , t=" ";
   getline(cin,s) ;
   for(int i = 0 ; i<s.size() ; i++){
         if (s[i]== ','){
         s.insert(i+1,t,0,1) ;
     }
    else if(s[i] == ' '){
        for(int j=i+1 ; j<s.size() ; j++){
            if(s[i]==s[j]){
                s.erase(j,1);
                j--;
            }
            else if(s[j]==','){s.erase(i,1);break ;}
            else
                break ;
        }
    }

}
cout<<s;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s , t=" ";
   getline(cin,s) ;
   for(int i = 0 ; i<s.size() ; i++){
         if(s[i]==','){
            s.insert(i+1,t,0,1) ;
         }
     if(s[i] == ' '){
        for(int j=i+1 ; j<s.size() ; j++){
            if(s[i]==s[j]){
                s.erase(j,1);
                j--;
            }
            else if(s[j]==','){s.erase(i,1);s.insert(i+1,t,0,1) ; break ;}
            else
                break ;
        }
    }

}
cout<<s;
}


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

int main(void)
{
	string str, u(".,!?"), tmp;
	vector<string> v;
	getline(cin, str);
	for (int i = 0; i != str.size(); ++i)
	{
		if (str[i] != ' ' && u.find(str[i]) == string::npos)
			tmp +=  str[i];
		else if (u.find(str[i]) != string::npos)
		{
			if (!tmp.empty())
			{
				v.push_back(tmp);
				tmp.clear();
			}
			v.push_back(string(1, str[i]));
		}

		if (!tmp.empty() && (str[i] == ' ' || i == str.size() - 1))
		{
			v.push_back(tmp);
			tmp.clear();
		}
	}

	for (int i = 0; i != v.size(); ++i)
	{
		cout << v[i];
		if (i != v.size()-1 && v[i+1].find_first_of(u) == string::npos)
			cout << ' ';
	}
	cout << endl;
	return 0;
}


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

bool stop(char c)
{
	return c=='.' || c==',' || c=='!' || c=='?';
}

bool letter(char c)
{
	return 'a'<=c && c<='z';
}

int main()
{
	string text;
	getline(cin, text);

	int i=0;
	while(i<text.length())
	{
		if(letter(text[i]))
		{
			cout << text[i];
		}
		else if(stop(text[i]))
		{
			cout << text[i];
			if(text[i+1]!=' ') cout << ' ';
		}
		else
		{
			if(letter(text[i+1]) )  cout << text[i];
		}
		i++;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <utility>
#include <cstring>

using namespace std;
typedef long long LL;
#define x1 gjigu
#define y1 djigd

int main() {
//    freopen("input.txt", "r", stdin);

    string s;
    getline(cin, s);
    vector<string> a;
    string cur;
    for (int i = 0; i < s.length(); ++i) {
        if (isalpha(s[i])) {
            cur += s[i];
        } else {
            if (cur != "") {
                a.push_back(cur);
                cur = "";
            }
            if (s[i] != ' ')
                a.push_back(string("") + s[i]);
        }
    }
    if (cur != "")
        a.push_back(cur);

    for (int i = 0; i+1 < a.size(); ++i) {
        if (i > 0 && isalpha(a[i-1][0]) && isalpha(a[i][0]))
            cout << " ";
        cout << a[i];
        if (a[i] == "." || a[i] == "," || a[i] == "!" || a[i] == "?")
            cout << " ";
    }

    if (a.size() > 1 && isalpha(a.back()[0]) && isalpha(a[a.size()-2][0]))
        cout << " ";
    cout << a.back() << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <utility>
#include <cstring>

using namespace std;
typedef long long LL;
#define x1 gjigu
#define y1 djigd

int main() {
//    freopen("input.txt", "r", stdin);

    string s;
    getline(cin, s);
    vector<string> a;
    string cur;
    for (int i = 0; i < s.length(); ++i) {
        if (isalpha(s[i])) {
            cur += s[i];
        } else {
            if (cur != "") {
                a.push_back(cur);
                cur = "";
            }
            if (s[i] != ' ')
                a.push_back(string("") + s[i]);
        }
    }
    if (cur != "")
        a.push_back(cur);

    for (int i = 0; i+1 < a.size(); ++i) {
        if (i > 0 && isalpha(a[i-1][0]) && isalpha(a[i][0]))
            cout << " ";
        cout << a[i];
        if (a[i] == "." || a[i] == "," || a[i] == "!" || a[i] == "?")
            cout << " ";
    }

    if (isalpha(a.back()[0]))
        cout << " ";
    cout << a.back() << endl;

    return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

vector<pair<int,int>>s;
int n, k;
string st;

int fn( int t ) {

	int sz = s.size(), i = t, j, mx = 0;

   while( i < sz ) {

   	j = i + 2;
   	int k1 = 0, res = s[i].sc;

   	while(1) {
   		if( j >= sz ) {
   			if( j-1 < sz ) {
   				res += min(s[j-1].sc,k-k1);
   				k1 = k;
   			}
   			break;
   		}
   		if( k1 + s[j-1].sc <= k ) {
   			res += s[j].sc + s[j-1].sc;
   			k1 += s[j-1].sc;
   		}
   		else {
   			res += min(s[j-1].sc,k-k1);
   			k1 = k;
   			break;
   		}
   		j += 2;
   	}
   	res += min(k-k1,s[i].fs);
   	i += 2;

   	mx = max(mx,res);
   }
   return mx;
}

int main() {
   fi;
   string st;
   int l2 = 1;

   cin>>n>>k>>st;
   int a = 0, b = 0;
   if( st[0] == 'a')a++;
   else b++;
   loop1(i,1,n) {
    if( st[i] == 'a')a++;
    else b++;
   	if( st[i] == st[i-1] )l2++;
   	else {
   		s.pb(mp(i-l2,l2));
   		l2 = 1;
   	}
   }
   if( k == a || k == b ) {
       cout<<n;
        return 0;
   }
   s.pb(mp(n-l2,l2));
   cout<<max(fn(0),fn(1));

   return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

vector<pair<int,int>>s;
int n, k;
string st;

int fn( int t ) {

	int sz = s.size(), i = t, j, mx = 0;

   while( i < sz ) {

   	j = i + 2;
   	int k1 = 0, res = s[i].sc;

   	while(1) {
   		if( j >= sz ) {
   			if( j-1 < sz && s[j-1].sc + k1 <= k )res += s[j-1].sc;
   			break;
   		}
   		int gap = s[j].fs - s[j-1].fs;
   		if( k1 + gap <= k ) {
   			res += s[j].sc + s[j-1].sc;
   			k1 += gap;
   		}
   		else
   			break;
   		j += 2;
   	}//cout<<i<<" "<<res<<"\n";
   	i += 2;
   	mx = max(mx,res);
   }
   return mx;
}

int main() {
   fi;
   string st;
   int l2 = 1;

   cin>>n>>k>>st;

   loop1(i,1,n) {
   	if( st[i] == st[i-1] )l2++;
   	else {
   		s.pb(mp(i-l2,l2));
   		l2 = 1;
   	}
   }
   s.pb(mp(n-l2,l2));
  	cout<<max(fn(0),fn(1));

   return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

vector<pair<int,int>>s;
int n, k;
string st;

int fn( int t ) {

	int sz = s.size(), i = t, j, mx = 0;

   while( i < sz ) {

   	j = i + 2;
   	int k1 = 0, res = s[i].sc;

   	while(1) {
   		if( j >= sz ) {
   			if( j-1 < sz ) {
   				res += min(s[j-1].sc,k-k1);
   				k1 = k;
   			}
   			break;
   		}
   		int gap = s[j].fs - s[j-1].fs;
   		if( k1 + gap <= k ) {
   			res += s[j].sc + s[j-1].sc;
   			k1 += gap;
   		}
   		else {
   			res += min(s[j-1].sc,k-k1);
   			k1 = k;
   			break;
   		}
   		j += 2;
   	}
   	res += min(k-k1,s[i].fs);
   	i += 2;

   	mx = max(mx,res);
   }
   return mx;
}

int main() {
   fi;
   string st;
   int l2 = 1;

   cin>>n>>k>>st;

   loop1(i,1,n) {
   	if( st[i] == st[i-1] )l2++;
   	else {
   		s.pb(mp(i-l2,l2));
   		l2 = 1;
   	}
   }

   s.pb(mp(n-l2,l2));
   cout<<max(fn(0),fn(1));

   return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

vector<pair<int,int>>s;
int n, k;
char st[100005];

int fn( int t ) {

	int sz = s.size(), i = t, j, mx = 0;

   while( i < sz ) {

   	j = i + 2;
   	int k1 = 0, res = s[i].sc;

   	while(1) {
   		if( j >= sz ) {
   			if( j-1 < sz ) {
   				res += min(s[j-1].sc,k-k1);
   				k1 = k;
   			}
   			break;
   		}
   		if( k1 + s[j-1].sc <= k ) {
   			res += s[j].sc + s[j-1].sc;
   			k1 += s[j-1].sc;
   		}
   		else {
   			res += min(s[j-1].sc,k-k1);
   			k1 = k;
   			break;
   		}
   		j += 2;
   	}
   	res += min(k-k1,s[i].fs);
   	i += 2;

   	mx = max(mx,res);
   }
   return mx;
}

int main() {
   fi;

   int l2 = 1;

   cin>>n>>k;
   cin>>st;

   int a = 0, b = 0;
   if( st[0] == 'a')a++;
   else b++;

   loop1(i,1,n) {
    if( st[i] == 'a')a++;
    else b++;

   	if( st[i] == st[i-1] )l2++;
   	else {
   		s.pb(mp(i-l2,l2));
   		l2 = 1;
   	}
   }

    if( k == a || k == b ) {
        cout<<n;
        return 0;
    }
   s.pb(mp(n-l2,l2));
   cout<<max(fn(0),fn(1));

   return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

int main() {
   fi;

   int n, k;
   string s;

   cin>>n>>k>>s;
   int dp[n][2], cost[n][2], ss[n][2], mx = 0;

   memset(dp,0,sizeof(dp));
   memset(cost,0,sizeof(cost));
   memset(ss,0,sizeof(ss));

   loop(i,n) {

   	if( i == 0 ) {
   		if( s[i] == 'a') {
   			dp[i][0] = 1;
   			ss[i][0] = 1;
   			if( k >= 1 )dp[i][1] = 1, cost[i][1] = 1;
   		}
   		else {
   			dp[i][1] = 1;
   			ss[i][1] = 1;
   			if( k >= 1 )dp[i][0] = 1, cost[i][0] = 1;
   		}
   	}

   	else {
   		if( s[i] == 'a') {
   			ss[i][0] = ss[i-1][0]+1;

   			dp[i][0] = dp[i-1][0] + 1;
   			cost[i][0] = cost[i-1][0];
   			if( k > cost[i-1][1] ) dp[i][1] = dp[i-1][1] + 1, cost[i][1] = cost[i-1][1] + 1;
   			else if( k == 1 ) dp[i][1] = ss[i-1][1]+1, cost[i][1] = 1;
   		}
   		else {
   			dp[i][1] = dp[i-1][1] + 1;
   			ss[i][1] = ss[i-1][1] + 1;
   			cost[i][1] = cost[i-1][1];
   			if( k > cost[i-1][0] ) dp[i][0] = dp[i-1][0] + 1, cost[i][0] = cost[i-1][0] + 1;
   			else if( k == 1 ) dp[i][0] = ss[i-1][0]+1, cost[i][0] = 1;

   		}
   	}
   	mx = max(mx,max(dp[i][0], dp[i][1]));

   }
	cout<<mx;
   return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

vector<pair<int,int>>s;
int n, k;
string st;

int fn( int t ) {

	int sz = s.size(), i = t, j, mx = 0;

   while( i < sz ) {

   	int z = 0;

   	while( z <= k && s[i].fs - z >= 0 && ( i == 0 ||  z < s[i-1].sc ) )  {
   	j = i + 2;
   	int k1 = 0, res = s[i].sc;

   	while(1) {
   		if( j >= sz ) {
   			if( j-1 < sz ) {
   				res += min(s[j-1].sc,k-k1);
   				k1 = k;
   			}
   			break;
   		}
   		int gap = s[j].fs - s[j-1].fs;
   		if( k1 + gap <= k ) {
   			res += s[j].sc + s[j-1].sc;
   			k1 += gap;
   		}
   		else {
   			res += min(s[j-1].sc,k-k1);
   			k1 = k;
   			break;
   		}
   		j += 2;
   	}
   	if( i > 0 && k1 < k ) res += min(k-k1,s[i-1].sc-z);
   	z++;
   	mx = max(mx,res);

   	}//cout<<i<<" "<<res<<"\n";

   	i += 2;

   }
   return mx;
}

int main() {
   fi;
   string st;
   int l2 = 1;

   cin>>n>>k>>st;

   loop1(i,1,n) {
   	if( st[i] == st[i-1] )l2++;
   	else {
   		s.pb(mp(i-l2,l2));
   		l2 = 1;
   	}
   }
   s.pb(mp(n-l2,l2));
   //loop(i,s.size())cout<<s[i].sc<<" ";
  	cout<<max(fn(0),fn(1));

   return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

vector<pair<int,int>>s;
int n, k;
string st;

int fn( int t ) {

	int sz = s.size(), i = t, j, mx = 0;

   while( i < sz ) {

   	j = i + 2;
   	int k1 = 0, res = s[i].sc;

   	while(1) {
   		if( j >= sz ) {
   			if( j-1 < sz ) {
   				res += min(s[j-1].sc,k-k1);
   				k1 = k;
   			}
   			break;
   		}
   		int gap = s[j].fs - s[j-1].fs;
   		if( k1 + gap <= k ) {
   			res += s[j].sc + s[j-1].sc;
   			k1 += gap;
   		}
   		else {
   			res += min(s[j-1].sc,k-k1);
   			k1 = k;
   			break;
   		}
   		j += 2;
   	}//cout<<i<<" "<<res<<"\n";
   	if( i > 0 && k1 < k ) res += min(k-k1,s[i-1].sc);
   	i += 2;

   	mx = max(mx,res);
   }
   return mx;
}

int main() {
   fi;
   string st;
   int l2 = 1;

   cin>>n>>k>>st;

   loop1(i,1,n) {
   	if( st[i] == st[i-1] )l2++;
   	else {
   		s.pb(mp(i-l2,l2));
   		l2 = 1;
   	}
   }
   s.pb(mp(n-l2,l2));
   //loop(i,s.size())cout<<s[i].sc<<" ";
  	cout<<max(fn(0),fn(1));

   return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

int main() {
   fi;

   int n, k;
   string s;

   cin>>n>>k>>s;
   int dp[n][2], cost[n][2], mx = 0;

   memset(dp,0,sizeof(dp));
   memset(cost,0,sizeof(cost));

   loop(i,n) {

   	if( i == 0 ) {
   		if( s[i] == 'a') {
   			dp[i][0] = 1;
   			if( k >= 1 )dp[i][1] = 1, cost[i][1] = 1;
   		}
   		else {
   			dp[i][1] = 1;
   			if( k >= 1 )dp[i][0] = 1, cost[i][0] = 1;
   		}
   	}

   	else {
   		if( s[i] == 'a') {
   			dp[i][0] = dp[i-1][0] + 1;
   			cost[i][0] = cost[i-1][0];
   			if( k > cost[i-1][1] ) dp[i][1] = dp[i-1][1] + 1, cost[i][1] = cost[i-1][1] + 1;
   			else if( k == 1 ) dp[i][1] = 1, cost[i][1] = 1;
   		}
   		else {
   			dp[i][1] = dp[i-1][1] + 1;
   			cost[i][1] = cost[i-1][1];
   			if( k > cost[i-1][0] ) dp[i][0] = dp[i-1][0] + 1, cost[i][0] = cost[i-1][0] + 1;
   			else if( k == 1 ) dp[i][0] = 1, cost[i][0] = 1;

   		}
   	}
   	mx = max(mx,max(dp[i][0], dp[i][1]));

   }
	cout<<mx;
   return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

int main() {
   fi;
   string s;
   int n, k;
   cin>>n>>k>>s;

   int l = 0, r = 1, mx = 0;

   while( l < n ) {
   	int k1 = 0, l1 = l;
   	r = l+1;
   	while( k1 <= k && r < n ) {
   		if( s[r] != s[l] && k1 == k ) {
   			r--;
   			break;
   		}
   		if( k1 < k && s[r] != s[l] )k1++;
   		if( k1 == 0 ) l1 = r;
   		r++;
   	}
   	if( r == n)r--;
   	mx = max(mx,r-l+1);
   	l = l1+1;
   }
   cout<<mx;

   return 0;
}


#include <bits/stdc++.h>

#define loop(i,n)    for( int i=0; i<n; i++ )
#define loop1(i,a,n) for( int i=a; i<n; i++ )
#define vloop(i,a)   for( vector<ll>::iterator i=a.begin(); i!=a.end(); i++ )
#define dloop(i,a)   for( deque<int>::iterator i=a.begin(); i!=a.end(); i++ )
#define PI 3.14159265
#define bc __builtin_popcountl
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb push_back
#define pf push_front
#define rf pop_front
#define rb pop_back
#define mp make_pair
#define fs first
#define sc second
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;

inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;}

vector<pair<int,int>>s;
int n, k;
char st[100005];

int fn( int t ) {

	int sz = s.size(), i = t, j, mx = 0;

   while( i < sz ) {

   	j = i + 2;
   	int k1 = 0, res = s[i].sc;

   	while(1) {
   		if( j >= sz ) {
   			if( j-1 < sz ) {
   				res += min(s[j-1].sc,k-k1);
   				k1 = k;
   			}
   			break;
   		}
   		if( k1 + s[j-1].sc <= k ) {
   			res += s[j].sc + s[j-1].sc;
   			k1 += s[j-1].sc;
   		}
   		else {
   			res += min(s[j-1].sc,k-k1);
   			k1 = k;
   			break;
   		}
   		j += 2;
   	}
   	res += min(k-k1,s[i].fs);
   	i += 2;

   	mx = max(mx,res);
   }
   return mx;
}

int main() {
   fi;

   int l2 = 1;

   cin>>n>>k;
   cin>>st;

   int a = 0, b = 0;
   if( st[0] == 'a')a++;
   else b++;

   loop1(i,1,n) {
    if( st[i] == 'a')a++;
    else b++;

   	if( st[i] == st[i-1] )l2++;
   	else {
   		s.pb(mp(i-l2,l2));
   		l2 = 1;
   	}
   }

    if( k >= a || k >= b ) {
        cout<<n;
        return 0;
    }
   s.pb(mp(n-l2,l2));
   cout<<max(fn(0),fn(1));

   return 0;
}


#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

#define ll long long

#define ub upper_bound

#define lb lower_bound

ll a[100001],b[100001],ans1,ans2;

int main()
{
	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll n,k,cnt1=0,cnt2=0;

	string str;

	cin>>n>>k;

	cin>>str;

	for(ll i=0;i<n;i++)
	{
		if(str[i]=='a')
		{
			if(i!=0)
			{
				b[i]=b[i-1]+1;

				a[i]=a[i-1];
			}

			else
			{
				b[i]=1;

				a[i]=0;
			}

			cnt1++;
		}

		else
		{
			if(i!=0)
			{
				a[i]=a[i-1]+1;

				b[i]=b[i-1];
			}

			else
			{
				a[i]=1;

				b[i]=0;
			}

			cnt2++;
		}
	}

	for(ll i=0;i<n-k;i++)
	{
		if(str[i]=='a')
		{
			if(ub(a+i,a+n,a[i]+k)-a>n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i);
		}

		else
		{
			if(ub(a+i,a+n,a[i]+k)-a-1 >n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i-1);
		}

		if(str[i]=='b')
		{
			if(ub(b+i,b+n,b[i]+k)-b >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i);
		}

		else
		{
			if(ub(b+i,b+n,b[i]+k)-b-1 >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i-1);
		}
	}

	if(n==1) cout<<"1"<<endl;

	else cout<<max(ans1,ans2)<<endl;

	return 0;
}


#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

#define ll long long

#define ub upper_bound

#define lb lower_bound

ll a[100001],b[100001],ans1,ans2;

int main()
{
	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll n,k,cnt1=0,cnt2=0;

	string str;

	cin>>n>>k;

	cin>>str;

	for(ll i=0;i<n;i++)
	{
		if(str[i]=='a')
		{
			if(i!=0)
			{
				b[i]=b[i-1]+1;

				a[i]=a[i-1];
			}

			else
			{
				b[i]=1;

				a[i]=0;
			}

			cnt1++;
		}

		else
		{
			if(i!=0)
			{
				a[i]=a[i-1]+1;

				b[i]=b[i-1];
			}

			else
			{
				a[i]=1;

				b[i]=0;
			}

			cnt2++;
		}
	}

	for(ll i=0;i<n-k;i++)
	{
		if(str[i]=='a')
		{
			if(ub(a+i,a+n,a[i]+k)-a>n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i);
		}

		else
		{
			if(ub(a+i,a+n,a[i]+k)-a-1 >n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i-1);
		}

		if(str[i]=='b')
		{
			if(ub(b+i,b+n,b[i]+k)-b >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i);
		}

		else
		{
			if(ub(b+i,b+n,b[i]+k)-b-1 >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i-1);
		}
	}

	if(n==1) cout<<"1"<<endl;

	else
	{
		if(cnt1==n||cnt2==n) cout<<"0"<<endl;

		else cout<<max(ans1,ans2)<<endl;
	}

	return 0;
}


#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

#define ll long long

#define ub upper_bound

#define lb lower_bound

ll a[100001],b[100001],ans1,ans2;

int main()
{
	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll n,k,cnt1=0,cnt2=0;

	string str;

	cin>>n>>k;

	cin>>str;

	for(ll i=0;i<n;i++)
	{
		if(str[i]=='a')
		{
			if(i!=0)
			{
				b[i]=b[i-1]+1;

				a[i]=a[i-1];
			}

			else
			{
				b[i]=1;

				a[i]=0;
			}

			cnt1++;
		}

		else
		{
			if(i!=0)
			{
				a[i]=a[i-1]+1;

				b[i]=b[i-1];
			}

			else
			{
				a[i]=1;

				b[i]=0;
			}

			cnt2++;
		}
	}

	for(ll i=0;i<n-k;i++)
	{
		if(str[i]=='a')
		{
			if(ub(a+i,a+n,a[i]+k)-a>n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i);
		}

		else
		{
			if(ub(a+i,a+n,a[i]+k)-a-1 >n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i-1);
		}

		if(str[i]=='b')
		{
			if(ub(b+i,b+n,b[i]+k)-b >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i);
		}

		else
		{
			if(ub(b+i,b+n,b[i]+k)-b-1 >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i-1);
		}
	}

	if(cnt1==n||cnt2==n) cout<<"0"<<endl;

	else cout<<max(ans1,ans2)<<endl;

	return 0;
}


#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

#define ll long long

#define ub upper_bound

#define lb lower_bound

ll a[100001],b[100001],ans1,ans2;

int main()
{
	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll n,k,cnt1=0,cnt2=0;

	string str;

	cin>>n>>k;

	cin>>str;

	for(ll i=0;i<n;i++)
	{
		if(str[i]=='a')
		{
			if(i!=0)
			{
				b[i]=b[i-1]+1;

				a[i]=a[i-1];
			}

			else
			{
				b[i]=1;

				a[i]=0;
			}

			cnt1++;
		}

		else
		{
			if(i!=0)
			{
				a[i]=a[i-1]+1;

				b[i]=b[i-1];
			}

			else
			{
				a[i]=1;

				b[i]=0;
			}

			cnt2++;
		}
	}

	if(n-k>0)
	{
		for(ll i=0;i<n-k;i++)
		{
			if(str[i]=='a')
			{
				if(ub(a+i,a+n,a[i]+k)-a>n-1) ans1=max(ans1,n-i);

				else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i);
			}

			else
			{
				if(ub(a+i,a+n,a[i]+k)-a-1 >n-1) ans1=max(ans1,n-i);

				else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i-1);
			}

			if(str[i]=='b')
			{
				if(ub(b+i,b+n,b[i]+k)-b >n-1) ans2=max(ans2,n-i);

				else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i);
			}

			else
			{
				if(ub(b+i,b+n,b[i]+k)-b-1 >n-1) ans2=max(ans2,n-i);

				else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i-1);
			}
		}

		if(cnt1==n||cnt2==n) cout<<n<<endl;

		else cout<<max(ans1,ans2)<<endl;
	}

	else cout<<n<<endl;

	return 0;
}


#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

#define ll long long

#define ub upper_bound

#define lb lower_bound

ll a[100001],b[100001],ans1,ans2;

int main()
{
	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll n,k,cnt1=0,cnt2=0;

	string str;

	cin>>n>>k;

	cin>>str;

	for(ll i=0;i<n;i++)
	{
		if(str[i]=='a')
		{
			if(i!=0)
			{
				b[i]=b[i-1]+1;

				a[i]=a[i-1];
			}

			else
			{
				b[i]=1;

				a[i]=0;
			}

			cnt1++;
		}

		else
		{
			if(i!=0)
			{
				a[i]=a[i-1]+1;

				b[i]=b[i-1];
			}

			else
			{
				a[i]=1;

				b[i]=0;
			}

			cnt2++;
		}
	}

	for(ll i=0;i<n-k;i++)
	{
		if(str[i]=='a')
		{
			if(ub(a+i,a+n,a[i]+k)-a>n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i);
		}

		else
		{
			if(ub(a+i,a+n,a[i]+k)-a-1 >n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i-1);
		}

		if(str[i]=='b')
		{
			if(ub(b+i,b+n,b[i]+k)-b >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i);
		}

		else
		{
			if(ub(b+i,b+n,b[i]+k)-b-1 >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i-1);
		}
	}

	 cout<<max(ans1,ans2)<<endl;

	return 0;
}


#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

#define ll long long

#define ub upper_bound

#define lb lower_bound

ll a[100001],b[100001],ans1,ans2;

int main()
{
	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll n,k,cnt1=0,cnt2=0;

	string str;

	cin>>n>>k;

	cin>>str;

	for(ll i=0;i<n;i++)
	{
		if(str[i]=='a')
		{
			if(i!=0)
			{
				b[i]=b[i-1]+1;

				a[i]=a[i-1];
			}

			else
			{
				b[i]=1;

				a[i]=0;
			}

			cnt1++;
		}

		else
		{
			if(i!=0)
			{
				a[i]=a[i-1]+1;

				b[i]=b[i-1];
			}

			else
			{
				a[i]=1;

				b[i]=0;
			}

			cnt2++;
		}
	}

	for(ll i=0;i<n-k;i++)
	{
		if(str[i]=='a')
		{
			if(ub(a+i,a+n,a[i]+k)-a>n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i);
		}

		else
		{
			if(ub(a+i,a+n,a[i]+k)-a-1 >n-1) ans1=max(ans1,n-i);

			else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i-1);
		}

		if(str[i]=='b')
		{
			if(ub(b+i,b+n,b[i]+k)-b >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i);
		}

		else
		{
			if(ub(b+i,b+n,b[i]+k)-b-1 >n-1) ans2=max(ans2,n-i);

			else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i-1);
		}
	}

	if(cnt1==n||cnt2==n) cout<<n<<endl;

	else cout<<max(ans1,ans2)<<endl;

	return 0;
}


#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

#define ll long long

#define ub upper_bound

#define lb lower_bound

ll a[100001],b[100001],ans1,ans2;

int main()
{
	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll n,k,cnt1=0,cnt2=0;

	string str;

	cin>>n>>k;

	cin>>str;

	for(ll i=0;i<n;i++)
	{
		if(str[i]=='a')
		{
			if(i!=0)
			{
				b[i]=b[i-1]+1;

				a[i]=a[i-1];
			}

			else
			{
				b[i]=1;

				a[i]=0;
			}

			cnt1++;
		}

		else
		{
			if(i!=0)
			{
				a[i]=a[i-1]+1;

				b[i]=b[i-1];
			}

			else
			{
				a[i]=1;

				b[i]=0;
			}

			cnt2++;
		}
	}

	if(n-k>0)
	{
		for(ll i=0;i<n-k;i++)
		{
			if(str[i]=='a')
			{
				if(ub(a+i,a+n,a[i]+k)-a>n-1) ans1=max(ans1,n-i);

				else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i);

				if(ub(b+i,b+n,b[i]+k-1)-b >n-1) ans2=max(ans2,n-i);

				else ans2=max(ans2,(ub(b+i,b+n,b[i]+k-1)-b)-i);
			}

			else
			{
				if(ub(a+i,a+n,a[i]+k-1)-a >n-1) ans1=max(ans1,n-i);

				else ans1=max(ans1,(ub(a+i,a+n,a[i]+k-1)-a)-i);

				if(ub(b+i,b+n,b[i]+k)-b >n-1) ans2=max(ans2,n-i);

				else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i);
			}
		}

		if(cnt1==n||cnt2==n) cout<<n<<endl;

		else cout<<max(ans1,ans2)<<endl;
	}

	else cout<<n<<endl;

	return 0;
}


#include <iostream>

#include <algorithm>

#include <string>

using namespace std;

#define ll long long

#define ub upper_bound

#define lb lower_bound

ll a[100001],b[100001],ans1,ans2;

int main()
{
	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll n,k,cnt1=0,cnt2=0;

	string str;

	cin>>n>>k;

	cin>>str;

	for(ll i=0;i<n;i++)
	{
		if(str[i]=='a')
		{
			if(i!=0)
			{
				b[i]=b[i-1]+1;

				a[i]=a[i-1];
			}

			else
			{
				b[i]=1;

				a[i]=0;
			}

			cnt1++;
		}

		else
		{
			if(i!=0)
			{
				a[i]=a[i-1]+1;

				b[i]=b[i-1];
			}

			else
			{
				a[i]=1;

				b[i]=0;
			}

			cnt2++;
		}
	}

	if(n-k>0)
	{
		for(ll i=0;i<n-k;i++)
		{
			cout<<ub(a+i,a+n,a[i]+k)-a<<"  jo  "<<endl;

			if(str[i]=='a')
			{
				if(ub(a+i,a+n,a[i]+k)-a>n-1) ans1=max(ans1,n-i);

				else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i);
			}

			else
			{
				if(ub(a+i,a+n,a[i]+k)-a-1 >n-1) ans1=max(ans1,n-i);

				else ans1=max(ans1,(ub(a+i,a+n,a[i]+k)-a)-i-1);
			}

			if(str[i]=='b')
			{
				if(ub(b+i,b+n,b[i]+k)-b >n-1) ans2=max(ans2,n-i);

				else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i);
			}

			else
			{
				if(ub(b+i,b+n,b[i]+k)-b-1 >n-1) ans2=max(ans2,n-i);

				else ans2=max(ans2,(ub(b+i,b+n,b[i]+k)-b)-i-1);
			}
		}

		if(cnt1==n||cnt2==n) cout<<n<<endl;

		else cout<<max(ans1,ans2)<<endl;
	}

	else cout<<n<<endl;

	return 0;
}


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

typedef vector<vector<int>> dp_table;

bool debug = false;

int dp(int i, int k, dp_table &table, const vector<int> &chunks) {
  if (i >= table.size()) {
    return 0;
  }

  if (i == table.size() - 1) {
    return chunks[i];
  }

  if (table[i][k] == -1) {
    table[i][k] = max(chunks[i], dp(i+1, k, table, chunks));

    if (k - chunks[i+1] >= 0) {
      int tmp = max(chunks[i] + chunks[i+1] + (i+2 < table.size() ? chunks[i+2] : 0), dp(i+3, k - chunks[i+1], table, chunks));
      table[i][k] = max(table[i][k], tmp);
    }

    if (debug)
    printf("%d %d %d\n", i, k, table[i][k]);
  }

  return table[i][k];
}

int main() {
  int n, k;
  cin >> n >> k;

  debug = (n == 8);

  string input;
  cin >> input;

  vector<int> chunks(2);
  chunks[0] = 0;
  chunks[1] = 1;
  for (int i = 1; i < input.size(); i++) {
    if (input[i] == input[i-1]) {
      chunks.back() += 1;
    } else {
      chunks.push_back(1);
    }
  }

  dp_table table(n, vector<int>(n+1, -1));

  cout << dp(0, k, table, chunks) << endl;

  return 0;
}


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

typedef vector<vector<int>> dp_table;

int dp(int i, int k, dp_table &table, const vector<int> &chunks) {
  if (i >= table.size()) {
    return 0;
  }

  if (i == table.size() - 1) {
    return chunks[i];
  }

  if (table[i][k] == -1) {
    table[i][k] = max(chunks[i], dp(i+1, k, table, chunks));

    if (k - chunks[i+1] >= 0) {
      int tmp = max(chunks[i] + chunks[i+1] + (i+2 < table.size() ? chunks[i+2] : 0), dp(i+3, k - chunks[i+1], table, chunks));
      table[i][k] = max(table[i][k], tmp);
    }

    printf("%d %d %d\n", i, k, table[i][k]);
  }

  return table[i][k];
}

int main() {
  int n, k;
  cin >> n >> k;

  string input;
  cin >> input;

  vector<int> chunks(2);
  chunks[0] = 0;
  chunks[1] = 1;
  for (int i = 1; i < input.size(); i++) {
    if (input[i] == input[i-1]) {
      chunks.back() += 1;
    } else {
      chunks.push_back(1);
    }
  }

  dp_table table(n, vector<int>(n+1, -1));

  cout << dp(0, k, table, chunks) << endl;

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;

  string input;
  cin >> input;

  int answer = 1;

  // Flip a
  for (int i_a = 0, i_b = 0, j = 0, count_a = 0, count_b = 0; j < input.size(); j++) {
    count_a += (input[j] == 'a');
    count_b += (input[j] == 'b');

    while (i_a < j && count_a > k) {
      count_a -= (input[i_a++] == 'a');
    }

    while (i_a < j && count_b > k) {
      count_b -= (input[i_b++] == 'b');
    }

    if (j - i_a + 1 > answer) {
      answer = j - i_a + 1;
    }

    if (j - i_b + 1 > answer) {
      answer = j - i_b + 1;
    }
  }

  printf("%d\n", answer);

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;

  string input;
  cin >> input;

  int answer = 1;

  // Flip a
  for (int i_a = 0, i_b = 0, j = 0, count_a = 0, count_b = 0; j < input.size(); j++) {
    count_a += (input[j] == 'a');
    count_b += (input[j] == 'b');

    while (i_a < j && count_a > k) {
      count_a -= (input[i_a] == 'a');
      i_a += 1;
    }

    while (i_b < j && count_b > k) {
      count_b -= (input[i_b] == 'b');
      i_b += 1;
    }

    if (j - i_a + 1 > answer) {
      answer = j - i_a + 1;
    }

    if (j - i_b + 1 > answer) {
      answer = j - i_b + 1;
    }
  }

  printf("%d\n", answer);

  return 0;
}


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

typedef vector<vector<int>> dp_table;

int dp(int i, int k, dp_table &table, const vector<int> &chunks) {
  if (i >= table.size()) {
    return 0;
  }

  if (i == table.size() - 1) {
    return chunks[i];
  }

  if (table[i][k] == -1) {
    table[i][k] = max(chunks[i], dp(i+1, k, table, chunks));

    if (k - chunks[i+1] >= 0) {
      int tmp = max(chunks[i] + chunks[i+1] + (i+2 < table.size() ? chunks[i+2] : 0), dp(i+3, k - chunks[i+1], table, chunks));
      table[i][k] = max(table[i][k], tmp);
    }
  }

  return table[i][k];
}

int main() {
  int n, k;
  cin >> n >> k;

  string input;
  cin >> input;

  vector<int> chunks(2);
  chunks[0] = 0;
  chunks[1] = 1;
  for (int i = 1; i < input.size(); i++) {
    if (input[i] == input[i-1]) {
      chunks.back() += 1;
    } else {
      chunks.push_back(1);
    }
  }

  dp_table table(chunks.size(), vector<int>(n+1, -1));

  cout << dp(0, k, table, chunks) << endl;

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;

  string input;
  cin >> input;

  int answer = 1;

  // Flip a
  for (int i = 0, j = 0, count = 0; j < input.size(); j++) {
    count += (input[j] == 'a');

    while (i < j && count > k) {
      count -= (input[i] == 'a');
      i += 1;
    }

    if (j - i + 1 > answer) {
      answer = j - i + 1;
    }
  }

  // Flip b
  for (int i = 0, j = 0, count = 0; j < input.size(); j++) {
    count += (input[j] == 'b');

    while (i < j && count > k) {
      count -= (input[i] == 'b');
      i += 1;
    }

    if (j - i + 1 > answer) {
      answer = j - i + 1;
    }
  }

  printf("%d\n", answer);

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;

  string input;
  cin >> input;

  int answer = 1;

  // Flip a
  for (int i = 0, j = 0, count = (input[0] == 'a'); j < input.size(); j++) {
    while (i < j && count > k) {
      count -= (input[i] == 'a');
      i += 1;
    }

    if (j - i + 1 > answer) {
      answer = j - i + 1;
    }
  }

  // Flip b
  for (int i = 0, j = 0, count = (input[0] == 'b'); j < input.size(); j++) {
    while (i < j && count > k) {
      count -= (input[i] == 'b');
      i += 1;
    }

    if (j - i + 1 > answer) {
      answer = j - i + 1;
    }
  }

  printf("%d\n", answer);

  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;

  string input;
  cin >> input;

  vector<int> a_count(1, input[0] == 'a'), b_count(1, input[0] == 'b');

  for (int i = 1; i < input.size(); i++) {
    a_count.push_back(a_count.back() + (input[i] == 'a'));
    b_count.push_back(b_count.back() + (input[i] == 'b'));
  }

  int answer = 1;
  // Flip a
  for (int i = 0, j = 0; j < input.size(); j++) {
    while (i < j && a_count[j] - (i ? a_count[i-1] : 0) > k) {
      i += 1;
    }

    if (j - i + 1 > answer) {
      answer = j - i + 1;
    }
  }

  for (int i = 0, j = 0; j < input.size(); j++) {
    while (i < j && b_count[j] - (i ? b_count[i-1] : 0) > k) {
      i += 1;
    }

    if (j - i + 1 > answer) {
      answer = j - i + 1;
    }
  }

  printf("%d\n", answer);

  return 0;
}


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

typedef vector<vector<int>> dp_table;

int dp(int i, int k, dp_table &table, const vector<int> &chunks) {
  if (i >= table.size()) {
    return 0;
  }

  if (i == table.size() - 1) {
    return chunks[i];
  }

  if (table[i][k] == -1) {
    table[i][k] = max(chunks[i], dp(i+1, k, table, chunks));

    if (k - chunks[i+1] >= 0) {
      int tmp = max(chunks[i] + chunks[i+1] + (i+2 < table.size() ? chunks[i+2] : 0), dp(i+3, k - chunks[i+1], table, chunks));
      table[i][k] = max(table[i][k], tmp);
    }
  }

  return table[i][k];
}

int main() {
  int n, k;
  cin >> n >> k;

  string input;
  cin >> input;

  vector<int> chunks(2);
  chunks[0] = 0;
  chunks[1] = 1;
  for (int i = 1; i < input.size(); i++) {
    if (input[i] == input[i-1]) {
      chunks.back() += 1;
    } else {
      chunks.push_back(1);
    }
  }

  dp_table table(n, vector<int>(n+1, -1));

  cout << dp(0, k, table, chunks) << endl;

  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,m,m1=0,sum=0,r=0,t=0,maxe=0,maxe1=0;
    int a[100005]={0};
    vector<int> v;
    string s;
cin>>n>>m;
cin>>s;
m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='a')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe<i-t)
            maxe=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='b'){i=j;t=j;m1=m;break;}}}

 }
 m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;m1=m;
    if(s[i]=='b')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe1<i-t)
            maxe1=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='a'){i=j;t=j;m1=m;break;}}}

}
if(max(maxe,maxe1)==0)maxe=s.size();
cout<<max(maxe,maxe1);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,m,m1=0,sum=0,r=0,t=0,maxe=0,maxe1=0;
    int a[100005]={0};
    vector<int> v;
    string s;
cin>>n>>m;
cin>>s;
m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='a')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe<i-t)
            maxe=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='b'){i=j;t=j;m1=m;break;}}}

 }
 m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='b')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe1<i-t)
            maxe1=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='a'){i=j;t=j;m1=m;break;}}}

}
m1=m;r=0;
for(int i=1;i<s.size();i++)
{
    if(s[i]==s[i-1])r++;
    else {if(m1>0) {r++;m1--;s[i]=s[i-1];}
        else {maxe1=max(r+1,maxe1);break;}}
        maxe1=max(r+1,max(maxe,maxe1));
}
cout<<max(maxe,maxe1);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,m,m1=0,sum=0,r=0,t=0,maxe=0,maxe1=0;
    int a[100005]={0};
    vector<int> v;
    string s;
cin>>n>>m;
cin>>s;
m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='a')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe<i-t)
            maxe=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='b'){i=j;t=j;m1=m;break;}}}

 }
 m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='b')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe1<i-t)
            maxe1=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='a'){i=j;t=j;m1=m;break;}}}

}
m1=m;r=0;
for(int i=1;i<s.size();i++)
{
    if(s[i]==s[i-1])r++;
    else {if(m1>0) {r++;m1--;s[i]=s[i-1];}
        else {maxe1=max(r+1,maxe1);break;}}
        maxe1=max(r+1,maxe1);
}
cout<<max(maxe,maxe1);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,m,m1=0,sum=0,r=0,t=0,maxe=0,maxe1=0;
    int a[100005]={0};
    vector<int> v;
    string s;
cin>>n>>m;
cin>>s;
m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='a')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe<i-t+1)
            maxe=i-t+1;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='b'){i=j;t=j;m1=m;break;}}}

 }
 m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;m1=m;
    if(s[i]=='b')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe1<i-t+1)
            maxe1=i-t+1;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='a'){i=j;t=j;m1=m;break;}}}

}
if(max(maxe,maxe1)==0)maxe=s.size();
cout<<max(maxe,maxe1);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,m,m1=0,sum=0,r=0,t=0,maxe=0,maxe1=0;
    int a[100005]={0};
    vector<int> v;
    string s;
cin>>n>>m;
cin>>s;
m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='a')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe<i-t)
            maxe=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='b'){i=j;t=j;m1=m;break;}}}

 }
 m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='b')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe1<i-t)
            maxe1=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='a'){i=j;t=j;m1=m;break;}}}

}
m1=m;r=0;
for(int i=1;i<s.size();i++)
{
    if(s[i]==s[i-1])r++;
    else {if(m1>0) {r++;m1--;s[i]=s[i-1];}
        else {maxe1=max(r,maxe1);break;}}
        maxe1=max((int)s.size(),max(maxe,maxe1));
}
cout<<max(maxe,maxe1);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,m,m1=0,sum=0,r=0,t=0,maxe=0,maxe1=0;
    int a[100005]={0};
    vector<int> v;
    string s;
cin>>n>>m;
cin>>s;
m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='a')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe<i-t)
            maxe=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='b'){i=j;t=j;m1=m;break;}}}

 }
 m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;m1=m;
    if(s[i]=='b')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe1<i-t)
            maxe1=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='a'){i=j;t=j;m1=m;break;}}}

}
if(min(maxe,maxe1)==0)maxe=s.size();
cout<<max(maxe,maxe1);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int abse(int r1){if(r1<0)return -1*r1;else return r1;}
int main()
{
    int n,m,m1=0,sum=0,r=0,t=0,maxe=0,maxe1=0;
    int a[100005]={0};
    vector<int> v;
    string s;
cin>>n>>m;
cin>>s;

for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='a')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe<i-t+2)
            maxe=i-t+2;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='b'){i=j;t=j+1;m1=m;break;}
        if(i==s.size()-1&&maxe==0){cout<<s.size();return 0;}}

}
 }
for(int i=0;i<s.size();i++)
{
    r=0;m1=m;
    if(s[i]=='b')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe1<i-t)
            maxe1=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='a'){i=j+1;t=j+1;m1=m;break;}}

}
}

cout<<max(maxe,maxe1);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int r=0;
int n,k;
string s;
int solve(char c,int x,int m)
{
    x=0;m=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]==c)x++;
        while(x>k){if(s[m]==c)x--;m++;}
        r=max(r,i-m+1);
    }

}
int main()
{

    cin>>n>>k;

    cin>>s;
    solve('a',0,0);
    solve('b',0,0);
    cout<<r;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,m,m1=0,sum=0,r=0,t=0,maxe=0,maxe1=0;
    int a[100005]={0};
    vector<int> v;
    string s;
cin>>n>>m;
cin>>s;
m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='a')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe<i-t)
            maxe=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='b'){i=j;t=j;m1=m;break;}}}

 }
 m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='b')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe1<i-t)
            maxe1=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='a'){i=j;t=j;m1=m;break;}}}

}
m1=m;r=0;
for(int i=1;i<s.size();i++)
{
    if(s[i]==s[i-1])r++;
    else {if(m1>0) {r++;m1--;s[i]=s[i-1];}
        else {maxe1=max(r,maxe1);break;}}
        maxe1=max(s.size(),max(maxe,maxe1));
}
cout<<max(maxe,maxe1);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int abse(int r1){if(r1<0)return -1*r1;else return r1;}
int main()
{
    int n,m,m1=0,sum=0,r=0,t=0,maxe=0,maxe1=0;
    int a[100005]={0};
    vector<int> v;
    string s;
cin>>n>>m;
cin>>s;
m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;
    if(s[i]=='a')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe<i-t)
            maxe=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='b'){i=j;t=j+1;m1=m;break;}}}

 }
 m1=m;
for(int i=0;i<s.size();i++)
{
    r=0;m1=m;
    if(s[i]=='b')r++;
    else m1--;
    if(m1<0)
    {
        if(maxe1<i-t)
            maxe1=i-t;
        for(int j=i-1;j>=0;j--)
        {if(s[j]=='a'){i=j;t=j+1;m1=m;break;}}}

}
if(max(maxe,maxe1)==0)maxe=s.size();
cout<<max(maxe,maxe1);

    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <sstream>
#include <utility>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

int N, K;
int rsq[100001];
string text;
deque<int> simp;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> K;

    cin >> text;

    for (int i = 0, j; i < text.size(); i++) {
        for (j = i; j < text.size() && text[i] == text[j]; j++);
        simp.pb(j - i);
        i = --j;
    }

    for (int i = 0; i < simp.size(); i++)
        rsq[i+1] = rsq[i] + simp[i];

    int res = 0;

    for (int i = 0; i < simp.size(); i++) {
        int cur = simp[i], cnt = K;
        for (int j = rsq[i+1]; j < text.size(); j++) {
            if (text[rsq[i]] != text[j]) {
                if (cnt == 0)
                    break;
                cnt--;
            }
            cur++;
        }
        res = max(res, cur);
    }

    cout << res << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <sstream>
#include <utility>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

int N, K;
int rsq[100001];
string text;
deque<int> simp;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> K;

    cin >> text;

    for (int i = 0, j; i < text.size(); i++) {
        for (j = i; j < text.size() && text[i] == text[j]; j++);
        simp.pb(j - i);
        i = --j;
    }

    int res = 0;

    for (int i = 0; i < simp.size(); i++) {
        int cur = 0, cnt = K;
        for (int j = i; j < simp.size(); j++) {
            if (!((j - i) % 2)) {
                cur += simp[j];
            } else {
                if (simp[j] < cnt) {
                    cur += simp[j];
                    cnt -= simp[j];
                } else  if (simp[j] == cnt) {
                    cur += cnt;
                    cnt = 0;
                } else {
                    cur += cnt;
                    break;
                }
            }
        }
        res = max(res, cur);
    }

    cout << res << endl;

    /**
    for (int i = 0; i < simp.size(); i++)
        rsq[i+1] = rsq[i] + simp[i];

    int res = 0;

    for (int i = 0; i < simp.size(); i++) {
        int cur = simp[i], cnt = K;
        for (int j = rsq[i+1]; j < text.size(); j++) {
            if (text[rsq[i]] != text[j]) {
                if (cnt == 0)
                    break;
                cnt--;
            }
            cur++;
        }
        res = max(res, cur);
    }

    cout << res << endl;
    **/

    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <sstream>
#include <utility>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

int N, K;
string text;
deque<int> simp;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> K;

    cin >> text;

    for (int i = 0, j; i < text.size(); i++) {
        for (j = i; j < text.size() && text[i] == text[j]; j++);
        simp.pb(j - i);
        i = --j;
    }

    int res = 0;

    for (int i = 0; i < simp.size(); i++) {
        int cur = simp[i], sum = 0;
        for (int j = 0; j <= i; j++)
            sum += simp[i];
        for (int i = sum; i < text.size(); i++) {
            cur++;
            if (text[i] != text[sum]) {
                if (K == 0)
                    break;
                K--;
            }
        }
        res = max(res, cur);
    }

    cout << res << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <sstream>
#include <utility>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

int res;
int del;
int a, b;
int N, K;
string text;

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> N >> K;
	cin >> text;

	for (int i = 0; i < text.size(); i++)
	{
		a += text[i] == 'a';	b += text[i] == 'b';

		if (min(a, b) <= K)
			res = max(res, a + b);
		else
			text[del++] == 'a' ? a-- : b--;
	}

	cout << res << endl;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <sstream>
#include <utility>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

int N, K;
int rsq[100001];
string text;
deque<int> simp;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> K;

    cin >> text;

    for (int i = 0, j; i < text.size(); i++) {
        for (j = i; j < text.size() && text[i] == text[j]; j++);
        simp.pb(j - i);
        i = --j;
    }

    int res = 0;

    for (int i = 0; i < simp.size(); i++) {
        int cur = 0, cnt = K;
        for (int j = i; j < simp.size(); j++) {
            if (!((j - i) % 2)) {
                cur += simp[j];
            } else {
                if (simp[j] < cnt) {
                    cur += simp[j];
                    cnt -= simp[j];
                } else  if (simp[j] == cnt) {
                    cur += cnt;
                    cnt = 0;
                } else {
                    cur += cnt;
                    break;
                }
            }
            i = j;
        }
        res = max(res, cur);
    }

    cout << res << endl;

    /**
    for (int i = 0; i < simp.size(); i++)
        rsq[i+1] = rsq[i] + simp[i];

    int res = 0;

    for (int i = 0; i < simp.size(); i++) {
        int cur = simp[i], cnt = K;
        for (int j = rsq[i+1]; j < text.size(); j++) {
            if (text[rsq[i]] != text[j]) {
                if (cnt == 0)
                    break;
                cnt--;
            }
            cur++;
        }
        res = max(res, cur);
    }

    cout << res << endl;
    **/

    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <sstream>
#include <utility>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

int res;
int a, b;
int N, K;
string text;

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> N >> K;
	cin >> text;

	for (int i = 0; i < text.size(); i++)
	{
		a += text[i] == a;	b += text[i] == b;

		if (min(a, b) <= K)
			res = max(res, a + b)
		else
			text[i-a-b] == 'a' ? a-- : b--;
	}

	cout << res << endl;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <sstream>
#include <utility>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

int res;
int a, b;
int N, K;
string text;

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> N >> K;
	cin >> text;

	for (int i = 0; i < text.size(); i++)
	{
		a += text[i] == a;	b += text[i] == b;

		if (min(a, b) <= K)
			res = max(res, a + b);
		else
			text[i-a-b] == 'a' ? a-- : b--;
	}

	cout << res << endl;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <sstream>
#include <utility>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

int N, K;
int rsq[100001];
string text;
deque<int> simp;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> N >> K;

    cin >> text;

    for (int i = 0, j; i < text.size(); i++) {
        for (j = i; j < text.size() && text[i] == text[j]; j++);
        simp.pb(j - i);
        i = --j;
    }

    for (int i = 0; i < simp.size(); i++)
        rsq[i+1] = rsq[i] + simp[i];

    int res = 0;

    for (int i = 0; i < simp.size(); i++) {
        int cur = simp[i], sum = rsq[i+1];
        /**
        for (int j = 0; j <= i; j++)
            sum += simp[i];
        **/
        for (int i = sum; i < text.size(); i++) {
            cur++;
            if (text[i] != text[sum]) {
                if (K == 0)
                    break;
                K--;
            }
        }
        res = max(res, cur);
    }

    cout << res << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <sstream>
#include <utility>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

#define f first
#define s second
#define mp make_pair
#define pb push_back

using namespace std;

int res;
int a, b;
int N, K;
string text;

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> N >> K;
	cin >> text;

	for (int i = 0; i < text.size(); i++)
	{
		a += text[i] == 'a';	b += text[i] == 'b';

		if (min(a, b) <= K)
			res = max(res, a + b);
		else
			text[i-a-b] == 'a' ? a-- : b--;
	}

	cout << res << endl;
}


import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static final String yes = "Yes";
    private static final String no = "No";

    public static void main(String[] args) throws IOException {

        Reader in = new Reader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n + 1];
        boolean[] know = new boolean[n + 1];

        int even = 0;
        int odd = 0;
        for (int i = 0; i <= n; i++) {
            String now = in.next();
            if (!now.equals("?")) {
                know[i] = true;
                a[i] = Integer.parseInt(now);
            } else {
                if (i % 2 == 0) {
                    even++;
                } else {
                    odd++;
                }
            }
        }

        if (k == 0) {
            if (know[0]) {
                out.println(a[0] == 0 ? yes : no);
            } else {
                if ((even + odd) % 2 == 0) {
                    out.println(no);
                } else {
                    out.println(yes);
                }
            }
        } else {
            if (even + odd == 0) {
                out.println(checkAnswer(a, k) ? yes : no);
            } else if ((even + odd) % 2 == 0) {
                if (odd - even > 0 && (odd - even) % 2 == 0) {
                    out.println(yes);
                } else {
                    out.println(no);
                }
            } else if ((even + odd) % 2 == 1) {
                if (odd - even > 0 && (odd - even) % 2 == 1) {
                    out.println(yes);
                } else {
                    out.println(no);
                }
            }
        }

        out.flush();
        in.close();
        out.close();
    }

    private static boolean checkAnswer(int[] a, int k) {
        int now = 0;
        int n = a.length - 1;
        for (int i = 0; i <= n - 1; i++) {
            now -= a[i];
            if (now % k != 0) return false;
            now = now / k;
//            System.err.println(now);
        }
//        System.err.println(a[n]);
        return a[n] == now;
    }

    static class Reader {
        BufferedReader reader;
        StringTokenizer st;

        Reader(InputStreamReader stream) {
            reader = new BufferedReader(stream);
            st = null;
        }

        void close() throws IOException {
            reader.close();
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() throws IOException {
            return reader.readLine();
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

    }
}


import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static final String yes = "Yes";
    private static final String no = "No";

    public static void main(String[] args) throws IOException {

        Reader in = new Reader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n + 1];
        boolean[] know = new boolean[n + 1];

        int sum = 0;
        for (int i = 0; i <= n; i++) {
            String now = in.next();
            if (!now.equals("?")) {
                know[i] = true;
                a[i] = Integer.parseInt(now);
            } else {
                sum++;
            }
        }

        int remain = n - sum;
        if (k == 0) {
            if (know[0]) {
                out.println(a[0] == 0 ? yes : no);
            } else {
                if (remain % 2 == 0) {
                    out.println(yes);
                } else {
                    out.println(no);
                }
            }
        } else {
            if (sum == 0) {
                out.println(checkAnswer(a, k) ? yes : no);
            } else if (remain % 2 == 0) {
                out.println(yes);
            } else {
                out.println(no);
            }
        }

        out.flush();
        in.close();
        out.close();
    }

    private static boolean checkAnswer(int[] a, int k) {
        int now = 0;
        int n = a.length - 1;
        for (int i = 0; i <= n - 1; i++) {
            now -= a[i];
            if (now % k != 0) return false;
            now = now / k;
//            System.err.println(now);
        }
//        System.err.println(a[n]);
        return a[n] == now;
    }

    static class Reader {
        BufferedReader reader;
        StringTokenizer st;

        Reader(InputStreamReader stream) {
            reader = new BufferedReader(stream);
            st = null;
        }

        void close() throws IOException {
            reader.close();
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() throws IOException {
            return reader.readLine();
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

    }
}


import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static final String yes = "Yes";
    private static final String no = "No";

    public static void main(String[] args) throws IOException {

        Reader in = new Reader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n + 1];
        boolean[] know = new boolean[n + 1];

        int sum = 0;
        for (int i = 0; i <= n; i++) {
            String now = in.next();
            if (!now.equals("?")) {
                know[i] = true;
                a[i] = Integer.parseInt(now);
            } else {
                sum++;
            }
        }

        int remain = n - sum;
        if (k == 0) {
            if (know[0]) {
                out.println(a[0] == 0 ? yes : no);
            } else {
                if (remain % 2 == 0) {
                    out.println(no);
                } else {
                    out.println(yes);
                }
            }
        } else {
            if (sum == 0) {
                out.println(checkAnswer(a, k) ? yes : no);
            } else if (remain % 2 == 0) {
                out.println(yes);
            } else {
                out.println(no);
            }
        }

        out.flush();
        in.close();
        out.close();
    }

    private static boolean checkAnswer(int[] a, int k) {
        int now = 0;
        int n = a.length - 1;
        for (int i = 0; i <= n - 1; i++) {
            now -= a[i];
            if (now % k != 0) return false;
            now = now / k;
//            System.err.println(now);
        }
//        System.err.println(a[n]);
        return a[n] == now;
    }

    static class Reader {
        BufferedReader reader;
        StringTokenizer st;

        Reader(InputStreamReader stream) {
            reader = new BufferedReader(stream);
            st = null;
        }

        void close() throws IOException {
            reader.close();
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() throws IOException {
            return reader.readLine();
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

    }
}


import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static final String yes = "Yes";
    private static final String no = "No";

    public static void main(String[] args) throws IOException {

        Reader in = new Reader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n + 1];
        boolean[] know = new boolean[n + 1];

        int sum = 0;
        for (int i = 0; i <= n; i++) {
            String now = in.next();
            if (!now.equals("?")) {
                know[i] = true;
                a[i] = Integer.parseInt(now);
            } else {
                sum++;
            }
        }

        if (k == 0) {
            if (know[0]) {
                out.println(a[0] == 0 ? yes : no);
            } else {
                int already = n + 1 - sum;
                if (already % 2 == 1) {
                    out.println(yes);
                } else {
                    out.println(no);
                }
            }
        } else {
            if (sum == 0) {
                out.println(checkAnswer(a, k) ? yes : no);
            } else if ((n + 1) % 2 == 0) {
                out.println(yes);
            } else {
                out.println(no);
            }
        }

        out.flush();
        in.close();
        out.close();
    }

    private static boolean checkAnswer(int[] a, int k) {
        int now = 0;
        int n = a.length - 1;
        for (int i = 0; i <= n - 1; i++) {
            now -= a[i];
            if (now % k != 0) return false;
            now = now / k;
//            System.err.println(now);
        }
//        System.err.println(a[n]);
        return a[n] == now;
    }

    static class Reader {
        BufferedReader reader;
        StringTokenizer st;

        Reader(InputStreamReader stream) {
            reader = new BufferedReader(stream);
            st = null;
        }

        void close() throws IOException {
            reader.close();
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() throws IOException {
            return reader.readLine();
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

    }
}


import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static final String yes = "Yes";
    private static final String no = "No";

    public static void main(String[] args) throws IOException {

        Reader in = new Reader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n + 1];
        boolean[] know = new boolean[n + 1];

        int sum = 0;
        for (int i = 0; i <= n; i++) {
            String now = in.next();
            if (!now.equals("?")) {
                know[i] = true;
                a[i] = Integer.parseInt(now);
            } else {
                sum++;
            }
        }

        if (k == 0) {
            if (know[0]) {
                out.println(a[0] == 0 ? yes : no);
            } else {
                if (sum % 2 == 0) {
                    out.println(yes);
                } else {
                    out.println(no);
                }
            }
        } else {
            if (sum == 0) {
                out.println(checkAnswer(a, k) ? yes : no);
            } else if ((n + 1) % 2 == 0) {
                out.println(yes);
            } else {
                out.println(no);
            }
        }

        out.flush();
        in.close();
        out.close();
    }

    private static boolean checkAnswer(int[] a, int k) {
        int now = 0;
        int n = a.length - 1;
        for (int i = 0; i <= n - 1; i++) {
            now -= a[i];
            if (now % k != 0) return false;
            now = now / k;
//            System.err.println(now);
        }
//        System.err.println(a[n]);
        return a[n] == now;
    }

    static class Reader {
        BufferedReader reader;
        StringTokenizer st;

        Reader(InputStreamReader stream) {
            reader = new BufferedReader(stream);
            st = null;
        }

        void close() throws IOException {
            reader.close();
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        String nextLine() throws IOException {
            return reader.readLine();
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair <ll,ll>
#define vl vector <ll>
#define vp vector <pair<ll,ll>>
#define sort(x) sort(x.begin(), x.end())
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,i,ch = 1,x = 0,d = 0;
    cin>>n>>k;
    ll a[n+1];
    char s[10];
    for(i=0;i<=n;i++)
    {
        cin>>s;
        if(s[0] == '?')
        {
            a[i] = -1;
            ch = 0;
        }
        else
        {
            d++;
            a[i] = atoi(s);
        }
    }
    if(k == 0)
    {
        if(a[0] == 0 or (a[i] == -1 and d%2 == 1))
            cout<<"Yes\n";
        else
            cout<<"No\n";
        return 0;
    }
    if(ch == 0)
    {
        if(n%2 == 0)
            cout<<"No\n";
        else
            cout<<"Yes\n";
        return 0;
    }
    x = a[0];
    for(i=1;i<=n;i++)
    {
        if(x%k != 0)
        {
            cout<<"No\n";
            return 0;
        }
        x = x/k;
        x += a[i];
    }
    if(x%k == 0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair <ll,ll>
#define vl vector <ll>
#define vp vector <pair<ll,ll>>
#define sort(x) sort(x.begin(), x.end())
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,i,ch = 1,x = 0,d = 0;
    cin>>n>>k;
    ll a[n+1];
    char s[10];
    for(i=0;i<=n;i++)
    {
        cin>>s;
        if(s[0] == '?')
        {
            a[i] = -1;
            ch = 0;
        }
        else
        {
            d++;
            a[i] = atoi(s);
        }
    }
    if(k == 0)
    {
        if(a[0] == 0 or (a[0] == -1 and d%2 == 1))
            cout<<"Yes\n";
        else
            cout<<"No\n";
        return 0;
    }
    if(ch == 0)
    {
        if(n%2 == 0)
            cout<<"No\n";
        else
            cout<<"Yes\n";
        return 0;
    }
    x = a[0];
    for(i=1;i<=n;i++)
    {
        if(x%k != 0)
        {
            cout<<"No\n";
            return 0;
        }
        x = x/k;
        x += a[i];
    }
    if(x%k == 0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair <ll,ll>
#define vl vector <ll>
#define vp vector <pair<ll,ll>>
#define sort(x) sort(x.begin(), x.end())
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,i,ch = 1,x = 0,d = 0;
    cin>>n>>k;
    ll a[n+1];
    char s[10];
    for(i=0;i<=n;i++)
    {
        cin>>s;
        if(s[0] == '?')
        {
            a[i] = 1000000;
            ch = 0;
        }
        else
        {
            d++;
            a[i] = atoi(s);
        }
    }
    if(k == 0)
    {
        if(a[0] == 0 or (a[0] == 1000000 and d%2 == 1))
            cout<<"Yes\n";
        else
            cout<<"No\n";
        return 0;
    }
    if(ch == 0)
    {
        if(n%2 == 0)
            cout<<"No\n";
        else
            cout<<"Yes\n";
        return 0;
    }
    x = a[0];
    for(i=1;i<=n;i++)
    {
        if(x%k != 0)
        {
            cout<<"No\n";
            return 0;
        }
        x = x/k;
        x += a[i];
    }
    if(x%k == 0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair <ll,ll>
#define vl vector <ll>
#define vp vector <pair<ll,ll>>
#define sort(x) sort(x.begin(), x.end())
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,i,ch = 1,x = 0,d = 0;
    cin>>n>>k;
    ll a[n+1];
    char s[10];
    for(i=0;i<=n;i++)
    {
        cin>>s;
        if(s[0] == '?')
        {
            a[i] = 1000000;
            ch = 0;
        }
        else
        {
            d++;
            a[i] = atoi(s);
        }
    }
    if(k == 0)
    {
        if(a[0] == 0 or (a[0] == 1000000 and d%2 == 1))
            cout<<"Yes\n";
        else
            cout<<"No\n";
        return 0;
    }
    if(ch == 0)
    {
        if(n%2 == 0)
            cout<<"No\n";
        else
            cout<<"Yes\n";
        return 0;
    }
    x = a[0];
    for(i=1;i<=n;i++)
    {
        if(x%k != 0)
        {
            cout<<"No\n";
            return 0;
        }
        x = x/k;
        x += a[i];
    }
    if(x == 0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair <ll,ll>
#define vl vector <ll>
#define vp vector <pair<ll,ll>>
#define sort(x) sort(x.begin(), x.end())
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,i,ch = 1,x = 0;
    cin>>n>>k;
    ll a[n+1];
    char s[10];
    for(i=0;i<=n;i++)
    {
        cin>>s;
        if(s[0] == '?')
            ch = 0;
        a[i] = atoi(s);
    }
    if(ch == 0)
    {
        if(n%2 == 0)
            cout<<"No\n";
        else
            cout<<"Yes\n";
        return 0;
    }
    x = a[0];
    for(i=1;i<=n;i++)
    {
        if(x%k != 0)
        {
            cout<<"No\n";
            return 0;
        }
        x = x/k;
        x += a[i];
    }
    if(x%k == 0)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const double eps = 1e-9;
const int inf = INT_MAX;
//////////////0123456789
const int N = 100004;
const ll mod1 = 1000000007;
const ll mod2 = 217645177;
const ll mod3 = inf;

ll x1[N], x2[N], x3[N], k;
int n;

int main() {
    cin >> n >> k;
    x1[0] = x2[0] = x3[0] = 1;
    for(int i = 1; i <= n; i++) {
        x1[i] = (x1[i-1]*k)%mod1;
        x2[i] = (x2[i-1]*k)%mod2;
        x3[i] = (x3[i-1]*k)%mod3;
    }

    char buf[17];
    bool full = true;
    bool a0 = false;
    int jog = 0;
    ll ans1 = 0, ans2 = 0, ans3 = 0;
    ll val;
    for(int i = 0; i < n+1; i++) {
        scanf(" %s",buf);
        if(buf[0] == '?'){
            full = false;
            if(!i) a0 = true;
        } else {
            jog++;
            ll tmp = atoll(buf);
            if(!i) val = tmp;
            ans1 = (ans1 + tmp*x1[i])%mod1;
            ans2 = (ans2 + tmp*x2[i])%mod2;
            ans3 = (ans3 + tmp*x3[i])%mod3;
        }
    }

    if(!k) {
        if(a0) {
            if(jog&1) puts("Yes");
            else puts("No");
        } else {
            if(!val) puts("Yes");
            else puts("No");
        }
    } else {
        if(full) {
            if(ans2 == 0) puts("Yes");
            else puts("No");
        } else {
            if(n&1) puts("Yes");
            else puts("No");
        }
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned int uint;
#define MAX 100055
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"Yes" : "No");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    x+=y; if (x>=mod) x-=mod;
}
void et() {
    puts("-1"); exit(0);
}

string a[MAX];
int cnt;
void fmain() {
//    scanf("%d%d", &n, &k);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>n>>k;
    for(int i=0;i<=n;i++) {
        cin>>a[i];
        if (a[i]=="?") cnt++;
    }
    bool myFirst = (n+1 - cnt) % 2 == 1;
    if (k==0) {
        bool fg = a[0]=="?";
        if (!fg) {
            etp(a[0]=="0");
        } else {
            etp(myFirst);
        }
    }
    if (cnt != 0) etp(n%2==1);
    else {
        ll pre = stoi(a[n]);
        for(int i=n-1;i>0;i--) {
            ll num = stoi(a[i]);
            if (abs(pre) <= 1e12)
            pre = num + k*pre;
        }
        pre *= -k;
        etp(pre==stoi(a[0]));
    }
}
int main() {
    fmain();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned int uint;
#define MAX 100055
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"Yes" : "No");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    x+=y; if (x>=mod) x-=mod;
}
void et() {
    puts("-1"); exit(0);
}

string a[MAX];
int cnt;
void fmain() {
//    scanf("%d%d", &n, &k);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    for(int i=0;i<=n;i++) {
        cin>>a[i];
        if (a[i]=="?") cnt++;
    }
    bool myFirst = (n+1 - cnt) % 2 == 1;
    if (k==0) {
        bool fg = a[0]=="?";
        if (!fg) {
            etp(a[0]=="0");
        } else {
            etp(myFirst);
        }
    }
    if (cnt != 0) etp(n%2==1);
    else {
        ll pre = stoi(a[n]);
        for(int i=n-1;i>0;i--) {
            ll num = stoi(a[i]);
            pre = num + k*pre;
        }
        pre *= -k;
        etp(pre==stoi(a[0]));
    }
}
int main() {
    fmain();
    return 0;
}


#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<x<<endl;
#define debugp(x) cerr<<#x<<"= {"<<x.first<<", "<<x.second<<"}"<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010;

ll to_int(string s){
	if (s[0]=='-') return -to_int(s.substr(1, s.size()));
	ll res=0;
	for (char ch:s) res=res*10+(ch-'0');
	return res;
}

int n, m, k, u, v, x, y, t, a, b, ans;
ll A[MAXN];
bool mark[MAXN];
string s;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>k;
	for (int i=0; i<=n; i++){
		cin>>s;
		if (s=="?"){
			mark[i]=1;
			t++;
		}
		else A[i]=to_int(s);
	}
	//debug(t)
	//for (int i=0; i<=n; i++) cerr<<A[i]<<' ';cerr<<endl;
	if (!t){
		for (int i=n; i; i--) A[i-1]+=A[i]*k, debug(A[i-1]);
		if (A[0]) kill("No")
		kill("Yes")
	}
	if (k){
		if ((n+1)%2) kill("No")
		kill("Yes")
	}
	if (mark[0]) kill("No")
	kill("Yes")

	return 0;
}
/*
          .---.                                                                     .---.              ...-'  |`. ..-'''-.       / .--. \        .-''-.
          |   |.--.                       .                     .                   |   |.--.          |      |  |\.-'''\ \     ' '    ' '     .' .-.  )
          |   ||__|                     .'|                   .'|                   |   ||__|          ....   |  |       | |    \ \    / /    / .'  / /
          |   |.--.                    <  |                  <  |                   |   |.--.            -|   |  |    __/ /      `.`'--.'    (_/   / /
    __    |   ||  |                     | |             __    | |             __    |   ||  |             |   |  |   |_  '.      / `'-. `.        / /
 .:--.'.  |   ||  |                 _   | | .'''-.   .:--.'.  | | .'''-.   .:--.'.  |   ||  |          ...'   `--'      `.  \   ' /    `. \      / /
/ |   \ | |   ||  |               .' |  | |/.'''. \ / |   \ | | |/.'''. \ / |   \ | |   ||  |          |         |`.      \ '. / /       \ '    . '
`" __ | | |   ||  |              .   | /|  /    | | `" __ | | |  /    | | `" __ | | |   ||  |          ` --------\ |       , || |         | |  / /    _.-')
 .'.''| | |   ||__|            .'.'| |//| |     | |  .'.''| | | |     | |  .'.''| | |   ||__|           `---------'        | || |         | |.' '  _.'.-''
/ /   | |_'---'              .'.'.-'  / | |     | | / /   | |_| |     | | / /   | |_'---'                                 / ,' \ \       / //  /.-'_.'
\ \._,\ '/                   .'   \_.'  | '.    | '.\ \._,\ '/| '.    | '.\ \._,\ '/                              -....--'  /   `.'-...-'.'/    _.'
 `--'  `"                               '---'   '---'`--'  `" '---'   '---'`--'  `"                               `.. __..-'       `-...-'( _.-'
*/


#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<x<<endl;
#define debugp(x) cerr<<#x<<"= {"<<x.first<<", "<<x.second<<"}"<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010;

ll to_int(string s){
	if (s[0]=='-') return -to_int(s.substr(1, s.size()));
	ll res=0;
	for (char ch:s) res=res*10+(ch-'0');
	return res;
}

int n, m, k, u, v, x, y, t, a, b, ans;
ll A[MAXN];
bool mark[MAXN];
string s;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>k;
	for (int i=0; i<=n; i++){
		cin>>s;
		if (s=="?"){
			mark[i]=1;
			t++;
		}
		else A[i]=to_int(s);
	}
	//debug(t)
	//for (int i=0; i<=n; i++) cerr<<A[i]<<' ';cerr<<endl;
	if (!t){
		for (int i=n; i; i--) A[i-1]+=A[i]*k;
		if (A[0]) kill("No")
		kill("Yes")
	}
	if (k){
		if ((n+1)%2) kill("No")
		kill("Yes")
	}
	if (mark[0]) kill("No")
	kill("Yes")

	return 0;
}
/*
          .---.                                                                     .---.              ...-'  |`. ..-'''-.       / .--. \        .-''-.
          |   |.--.                       .                     .                   |   |.--.          |      |  |\.-'''\ \     ' '    ' '     .' .-.  )
          |   ||__|                     .'|                   .'|                   |   ||__|          ....   |  |       | |    \ \    / /    / .'  / /
          |   |.--.                    <  |                  <  |                   |   |.--.            -|   |  |    __/ /      `.`'--.'    (_/   / /
    __    |   ||  |                     | |             __    | |             __    |   ||  |             |   |  |   |_  '.      / `'-. `.        / /
 .:--.'.  |   ||  |                 _   | | .'''-.   .:--.'.  | | .'''-.   .:--.'.  |   ||  |          ...'   `--'      `.  \   ' /    `. \      / /
/ |   \ | |   ||  |               .' |  | |/.'''. \ / |   \ | | |/.'''. \ / |   \ | |   ||  |          |         |`.      \ '. / /       \ '    . '
`" __ | | |   ||  |              .   | /|  /    | | `" __ | | |  /    | | `" __ | | |   ||  |          ` --------\ |       , || |         | |  / /    _.-')
 .'.''| | |   ||__|            .'.'| |//| |     | |  .'.''| | | |     | |  .'.''| | |   ||__|           `---------'        | || |         | |.' '  _.'.-''
/ /   | |_'---'              .'.'.-'  / | |     | | / /   | |_| |     | | / /   | |_'---'                                 / ,' \ \       / //  /.-'_.'
\ \._,\ '/                   .'   \_.'  | '.    | '.\ \._,\ '/| '.    | '.\ \._,\ '/                              -....--'  /   `.'-...-'.'/    _.'
 `--'  `"                               '---'   '---'`--'  `" '---'   '---'`--'  `"                               `.. __..-'       `-...-'( _.-'
*/