#include <iostream>
#include<algorithm>
#include<cstdio>
#include<math.h>
using namespace std;
const int maxn=100005;
int main()
{
    int m,q,minq=1000000,n,a[maxn];
    cin>>m;
    for(int i=0;i<m;i++)
    {
        scanf("%d",&q);
        minq=min(minq,q);
    }
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sort(a,a+n);
    int ans=0;
    for(int i=n-m;i>=0;i-=(m+2))
    {
        //cout<<"i: "<<i<<endl;
        //cout<<i-(m)<<" "<<i-(m+1)<<endl;
        if(i-1>=0) ans+=a[i-1];
        if(i-2>=0) ans+=a[i-2];
    }
    ans=sum-ans;
    cout<<ans<<endl;
    cin>>n;
    //cout << "Hello world!" << endl;
    return 0;
}


#include <iostream>
#include<algorithm>
#include<cstdio>
#include<math.h>
using namespace std;
const int maxn=100005;
int main()
{
    int m,q,minq=1000000,n,a[maxn];
    cin>>m;
    for(int i=0;i<m;i++)
    {
        scanf("%d",&q);
        minq=min(minq,q);
    }
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sort(a,a+n);
    int ans=0;
    for(int i=n-minq;i>=0;i-=(minq+2))
    {
        //cout<<"i: "<<i<<endl;
        //cout<<i-(m)<<" "<<i-(m+1)<<endl;
        if(i-1>=0) ans+=a[i-1];
        if(i-2>=0) ans+=a[i-2];
    }
    ans=sum-ans;
    cout<<ans<<endl;
    cin>>n;
    //cout << "Hello world!" << endl;
    return 0;
}


#include <iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn=100005;
int main()
{
    int m,q,minq=INT_MAX,n,a[maxn];
    cin>>m;
    for(int i=0;i<m;i++)
    {
        scanf("%d",&q);
        minq=min(minq,q);
    }
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sort(a,a+n);
    int ans=0;
    for(int i=n-1;i>=0;i-=(m+2))
    {
        //cout<<"i: "<<i<<endl;
        if(i-(m+1)>=0) ans+=a[i-(m+1)];
        if(i-(m+2)>=0) ans+=a[i-(m+2)];
    }
    ans=sum-ans;
    cout<<ans<<endl;
    //cout << "Hello world!" << endl;
    return 0;
}


#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define inf 1000000000
#define mod 1000000007
#define ll long long
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int m,n;
int mn=inf;
int a[100005];
ll ans;
int main()
{
    m=read();
    for(int i=1;i<=m;i++)
    {
        int x=read();mn=min(mn,x);
    }
    n=read();
    for(int i=1;i<=n;i++)
    {
        a[i]=read();
        ans+=a[i];
    }
    sort(a+1,a+n+1);
    for(int i=n-mn;i>=1;i-=(mn+2))
    {
        ans-=a[i];
        if(i>=2)ans-=a[i-1];
    }
    cout<<ans;
    return 0;
}


#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<cstdio>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define inf 1000000000
#define mod 1000000007
#define ll long long
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int m,n;
int mn=inf;
int a[100005];
ll ans;
int main()
{
    m=read();
    for(int i=1;i<=m;i++)
    {
        int x=read();mn=min(mn,x);
    }
    n=read();
    for(int i=1;i<=n;i++)
    {
        a[i]=read();
        ans+=a[i];
    }
    sort(a+1,a+n+1);
    for(int i=n-mn-1;i>=1;i-=(mn+2))
        ans-=a[i]+a[i+1];
    cout<<ans;
    return 0;
}


	#include <bits/stdc++.h>
	using namespace std;
	#define all(x) (x).begin(), (x).end()
	#define sz(x) (int)x.size()
	#define len(x) (int)x.length()
	#define ac(x, i) get<i>(x)
	#define pb push_back
	#define mp make_pair
	#define pii pair<int, int>
	#define pll pair<ll ,ll>
	#define pli pair<ll, int>
	#define ff first
	#define ss second
	#define trace(x)    cerr << #x << ": " << x << "\n"
	#define trav0(a, n) cerr << #a << "[" << n <<  "] = ["; for (int i = 0; i < n; i++) cerr << a[i] << ", "; cerr << "]\n"
	#define trav1(a, n) cerr << #a << "[" << n <<  "] = ["; for (int i = 1; i <= n; i++) cerr << a[i] << ", "; cerr << "]\n"
	#define trap0(a, n) cerr << #a << "[" << n <<  "] = ["; for (int i = 0; i < n; i++) cerr << "(" << a[i].ff << ", " << a[i].ss << "), "; cerr << "]\n"
	#define trap1(a, n) cerr << #a << "[" << n <<  "] = ["; for (int i = 1; i <= n; i++) cerr << "(" << a[i].ff << ", " << a[i].ss << "), "; cerr << "]\n"
	#define travMap(a)  cerr << #a << "[" << sz(a) <<  "] = ["; for (auto i : a) cerr << "(" << i.ff << ", " << i.ss << "), "; cerr << "]\n"
	#define traverse(a) cerr << #a << "[" << sz(a) <<  "] = ["; for (auto i : a) cerr << i << ", "; cerr << "]\n"
	#define random_permute(x) shuffle(all(x), mt)
	#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
	#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
	#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
	#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
	#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
	#define FOREACH(a, b) for (auto&(a) : (b))
	#define REP(i, n) FOR(i, 0, n)
	#define REPN(i, n) FORN(i, 1, n)

	typedef unsigned int uint;
	typedef long long int ll;
	typedef unsigned long long int ull;
	typedef vector<int> vi;
	typedef vector<ll> vl;
	typedef vector<pii> vii;
	typedef vector<pll> vll;
	typedef vector<bool> vb;
	typedef vector<string> vs;
	const int infi = 1e9;
	const ll infl = 1e18;
	const int MOD = 1e9 + 7;
	//template <typename Map> bool map_compare (Map const &lhs, Map const &rhs) { return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin());}
	//auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
	//mt19937 mt(seed);
	//int randint(int p = MOD) { return mt() % p;}
	//ll randlong(ll p = infl) { return mt() % p;}
	ll log_2 (ll n) { return (n > 1ll)? 1ll + log_2(n/2): 0ll;}
	inline void add(ll&a, ll b) {a += b; if (a >= MOD) a -= MOD;}
	inline void sub(ll&a, ll b) {a -= b; if (a < 0) a += MOD;}

	/* CONVERT A INTEGER TO A STRING */

	inline string IntToString(ll a)
	{
	    char x[100];
	    sprintf(x, "%lld", a);
	    string s = x;
	    return s;
	}

	/* CONVERT A STRING TO AN INTEGER */

	inline ll StringToInt(string a)
	{
	    char x[100];
	    ll res;
	    strcpy(x, a.c_str());
	    sscanf(x, "%lld", &res);
	    return res;
	}

	/* TO ENTER A STRING AS A CHARACTER ARRAY AND THEN CONVERT IT TO A SINGLE STRING */

	inline string GetString(void)
	{
	    char x[1000005];
	    scanf("%s", x);
	    string s = x;
	    return s;
	}

	/* CONVERT A STRING TO UPPER CASE */

	inline string uppercase(string s)
	{
	    int n = sz(s);
	    REP(i, n)
	    if (s[i] >= 'a' && s[i] <= 'z')
	        s[i] = s[i] - 'a' + 'A';
	    return s;
	}

	/* CONVERT A STRING TO LOWER CASE */

	inline string lowercase(string s)
	{
	    int n = sz(s);
	    REP(i, n)
	    if (s[i] >= 'A' && s[i] <= 'Z')
	        s[i] = s[i] - 'A' + 'a';
	    return s;
	}

	inline void OPEN(string s)
	{
	#ifndef TESTING
	    freopen((s + ".in").c_str(), "r", stdin);
	    freopen((s + ".out").c_str(), "w", stdout);
	#endif
	}

	/* TO DISPLAY AN ARRAY ON THE SCREEN */

	void showarr(ll arr[],ll n)
	{
		int i;
		for(i=0;i<n;i++)
		{
			cout<<arr[i]<<" ";
		}
		cout<<endl;
	  }

	/*TO DISPLAY A VECTOR OF INTERGERS */

	void showvec(vector <ll> v)
	{
		int i;
		for(i=0;i<v.size();i++)
		{
			cout<<v[i]<<" ";
		}
		cout<<endl;
	  }

	/* TO CHECK IF A STRING IS PALINDROME*/

	  int isPalindrome(string str)
	{
	    int l = 0;
	    int h = str.length() - 1;
	  while (h > l)
	    {
	        if (str[l++] != str[h--] )
	        {
	            return 0;
	        }
	    }
	    return 1;
	}

	/*   DISPLAY A VECTOR OF PAIRS */

	  void showvecpair(vll v)
	  {
	  	for(int i=0;i<sz(v);i++)
	  	{
	  		cout<<v[i].first<<" "<<v[i].second<<endl;
		  }
	  }

	/*   TO SORT A VECTOR OF PAIRS VIA SECOND ELEMENT.........CHECK NOTEPAD */

	bool sortbysec(const pll &a,
	              const pll &b)
	{
	    return (a.second < b.second);
	}

	/*   TO PRINT BINARY REPRESENTATION OF ANY NUMBER */

	void bin(unsigned n)
	{
	    unsigned i;
	    for (i = 1 << 31; i > 0; i = i / 2)
	        (n & i)? printf("1"): printf("0");
	}

	/*   TO COUNT NUMBER OF SET BITS IN BINARY REPRESENTATION OF ANY NUMBER */

	ll cntset(ll n)
	{
		bitset<64> b1(n);  //represents in 64 bit format
		return b1.count();
	}

	// end of Sektor_jr template v2.0.3 (BETA)

	 bool comparison(const pair<int,int> &a,const pair<int,int> &b){
	    return (abs(a.first)+abs(a.second))<(abs(b.second)+abs(b.first));
	}

	void solve()
	{
		long long int min=INT_MAX,m,l,r,a=0,b=0,c,d,n,i,j,max=INT_MIN,ctr=0,cnt=0,x=0;
		cin>>m;
		vl q(m);
		for(i=0;i<m;i++)
		{
			cin>>q[i];
		}
		cin>>n;
		vl v(n);

		for(i=0;i<n;i++)
		{
			cin>>v[i];
		}
		sort(q.begin(),q.end());
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		x=q[0];
		for(i=0;i<n;i++)
		{
			cnt=cnt+v[i];
			ctr++;
			if(ctr==x)
			{
				ctr=0;
				i=i+2;
			}
		}
		cout<<cnt<<endl;
	}

	int main()
	{
	    ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    int i,T;

	   	T=1;
		//cin>>T;

	    for(i=1;i<=T;i++)
	    {
	    	solve();
		}
	    return 0;

	}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>

using namespace std;

typedef vector<int> vi;
typedef stack<int> ski;

int main()
{
    int disc,itmc,min_disc,res=0,curr;
    vi discount,item;
    cin>>disc;
    discount.resize(disc);
    for(int i=0;i<disc;i++)
        cin>>discount[i];
    cin>>itmc;
    item.resize(itmc);
    for(int i=0;i<itmc;i++)
        cin>>item[i];
    sort(discount.begin(),discount.end());
    sort(item.begin(),item.end());
    min_disc=discount[0];
    curr=itmc;
    while(1)
    {
        if(curr<min_disc)
            break;
        for(int i=curr-1;i>curr-min_disc-1;i--)
            res+=item[i];
        curr-=min_disc;
        if(curr>=2)
            curr-=2;
        else if(curr>=1)
            curr--;
    }
    for(int i=0;i<curr;i++)
        res+=item[i];
    cout<<res;
}
/*
1
2
4
50 50 100 100
output
200
*/


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef vector<int> vi;

int main()
{
    int disc,itmc,min_disc=1e8,res=0,curr;
    vi item;
    cin>>disc;
    for(int i=0;i<disc;i++)
    {
        int temp;
        cin>>temp;
        min_disc=min(min_disc,temp);
    }
    cin>>itmc;
    item.resize(itmc);
    for(int i=0;i<itmc;i++)
        cin>>item[i];
    sort(item.begin(),item.end());
    curr=itmc;
    while(1)
    {
        if(curr<min_disc)
            break;
        for(int i=curr-1;i>curr-min_disc-1;i--)
            res+=item[i];
        curr-=min_disc;
        if(curr>=2)
            curr-=2;
        else if(curr>=1)
            curr--;
    }
    for(int i=0;i<curr;i++)
        res+=item[i];
    cout<<res;
}


#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
template
<class T>
istream& operator>>(istream& in, vector<T>& arr){
    for(auto& el : arr)
        in >> el;
    return in;
}

template
<class T>
ostream& operator<<(ostream& out, vector<T>& arr){
    for(auto& el : arr)
        out << el << ' ';
    return out;
}

int main(void)
{
    int k, n, low;
    cin >> k;
    vector<int> ds(k);
    cin >> ds >> n;
    vector<int> ps(n);
    cin >> ps;
    sort(all(ds));
    sort(all(ps));
    low = ds[0];
    long long sum = 0;
    for (int i = n - 1; i >= 0; i -= (low + 2))
    {
        for (int j = i; j >= 0 && j > i - low; j--)
        {
            sum += ps[j];
        }
    }
    printf("%d\n", sum);
}


#include<bits/stdc++.h>

using namespace std;

int m,n;
int prices[100005];

int cmp(int a,int b){
    return a>b;
}

int main(){
    cin >> m;
    int in;
    int min_discount=INT_MAX;
    for(int i=0;i<m;i++){
        cin >> in;
        min_discount=min(min_discount,in);
    }
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> prices[i];
    }
    sort(prices,prices+n,cmp);
    int i=0;
    long long zbr=0;
    for(int i=0;i<n;i+=(min_discount+2)){
        for(int j=0;j<min_discount;j++){
            if(i+j>=n){
                break;
            }
            zbr+=prices[i+j];
        }
    }
    cout << zbr<<endl;
}


#include<bits/stdc++.h>

using namespace std;

int m,n;
int prices[100005];

int cmp(int a,int b){
    return a>b;
}

int main(){
    cin >> m;
    int in;
    int min_discount=INT_MAX;
    for(int i=0;i<m;i++){
        cin >> in;
        min_discount=min(min_discount,in);
    }
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> prices[i];
    }
    sort(prices,prices+n,cmp);
    int i=0;
    long long zbr=0;
    for(int i=0;i<n;i+=(min_discount+2)){
        for(int j=0;j<min_discount;j++){
            zbr+=prices[i+j];
        }
    }
    cout << zbr<<endl;
}


#include<cstdio>
int main(){
    int n; scanf("%d",&n);
    n/=1000;
    puts(n&1 ? "1" : "3");
    return 0;
}


#include <stdio.h>
int main() {
    int n;
    scanf("%d", &n);
    n/=1000;
    puts(n & 1 ? "1" : "3");
    return 0;
}


#include<cstdio>
int main()
{
    int n;
    scanf("%d", &n);
    n /= 1000;
    puts(n & 1 ? "1" : "3");
    return 0;
}


import java.util.*;

public class cf207d {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt() / 1000;
    if(n % 2 == 0) System.out.println(3);
    else System.out.println(1);
  }
}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class magic2 {
	public static void main(String[] args) throws Exception{
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		if(N<2000||N==17000||N==20000||N==21000||N==25000||N==27000||N==18000||N==19000||N==7000||N==10000||N==54000||N==55000||N==56000)out.println("1");
		else if(N<=3000||N==22000||N==23000||N==24000||N==8000||N==9000||N==51000||N==52000||N==53000)out.println("2");
		else out.println("3");
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) throws Exception{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer(br.readLine().trim());
		}
		public int numTokens() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return numTokens();
			}
			return st.countTokens();
		}
		public boolean hasNext() throws Exception{
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return hasNext();
			}
			return true;
		}
		public String next() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return next();
			}
			return st.nextToken();
		}
		public double nextDouble() throws Exception{
			return Double.parseDouble(next());
		}
		public float nextFloat() throws Exception{
			return Float.parseFloat(next());
		}
		public long nextLong() throws Exception{
			return Long.parseLong(next());
		}
		public int nextInt() throws Exception{
			return Integer.parseInt(next());
		}
		public String nextLine() throws Exception{
			return br.readLine();
		}
	}

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class magic2 {
	public static void main(String[] args) throws Exception{
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		if(N<2000||N==17000||N==20000||N==21000||N==25000||N==29000||N==27000||N==18000||N==19000||N==7000||N==10000||N==54000||N==55000||N==56000)out.println("1");
		else if(N<=3000||N==22000||N==23000||N==24000||N==8000||N==9000||N==51000||N==52000||N==53000)out.println("2");
		else out.println("3");
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) throws Exception{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer(br.readLine().trim());
		}
		public int numTokens() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return numTokens();
			}
			return st.countTokens();
		}
		public boolean hasNext() throws Exception{
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return hasNext();
			}
			return true;
		}
		public String next() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return next();
			}
			return st.nextToken();
		}
		public double nextDouble() throws Exception{
			return Double.parseDouble(next());
		}
		public float nextFloat() throws Exception{
			return Float.parseFloat(next());
		}
		public long nextLong() throws Exception{
			return Long.parseLong(next());
		}
		public int nextInt() throws Exception{
			return Integer.parseInt(next());
		}
		public String nextLine() throws Exception{
			return br.readLine();
		}
	}

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class magic2 {
	public static void main(String[] args) throws Exception{
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		if(N<2000||N==17000||N==20000||N==21000||N==25000||N==26000||N==27000||N==18000||N==19000||N==7000||N==10000||N==54000||N==55000||N==56000)out.println("1");
		else if(N<=3000||N==22000||N==23000||N==24000||N==8000||N==9000||N==51000||N==52000||N==53000)out.println("2");
		else out.println("3");
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) throws Exception{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer(br.readLine().trim());
		}
		public int numTokens() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return numTokens();
			}
			return st.countTokens();
		}
		public boolean hasNext() throws Exception{
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return hasNext();
			}
			return true;
		}
		public String next() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return next();
			}
			return st.nextToken();
		}
		public double nextDouble() throws Exception{
			return Double.parseDouble(next());
		}
		public float nextFloat() throws Exception{
			return Float.parseFloat(next());
		}
		public long nextLong() throws Exception{
			return Long.parseLong(next());
		}
		public int nextInt() throws Exception{
			return Integer.parseInt(next());
		}
		public String nextLine() throws Exception{
			return br.readLine();
		}
	}

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class magic2 {
	public static void main(String[] args) throws Exception{
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		if(N<2000||N==17000||N==20000||N==21000||N==25000||N==18000||N==19000||N==7000||N==10000||N==54000||N==55000||N==56000)out.println("1");
		else if(N<=3000||N==22000||N==23000||N==24000||N==8000||N==9000||N==51000||N==52000||N==53000)out.println("2");
		else out.println("3");
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) throws Exception{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer(br.readLine().trim());
		}
		public int numTokens() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return numTokens();
			}
			return st.countTokens();
		}
		public boolean hasNext() throws Exception{
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return hasNext();
			}
			return true;
		}
		public String next() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return next();
			}
			return st.nextToken();
		}
		public double nextDouble() throws Exception{
			return Double.parseDouble(next());
		}
		public float nextFloat() throws Exception{
			return Float.parseFloat(next());
		}
		public long nextLong() throws Exception{
			return Long.parseLong(next());
		}
		public int nextInt() throws Exception{
			return Integer.parseInt(next());
		}
		public String nextLine() throws Exception{
			return br.readLine();
		}
	}

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class magic2 {
	public static void main(String[] args) throws Exception{
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		if(N<2000)out.println("1");
		else if(N<=3000)out.println("2");
		else out.println("3");
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) throws Exception{
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer(br.readLine().trim());
		}
		public int numTokens() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return numTokens();
			}
			return st.countTokens();
		}
		public boolean hasNext() throws Exception{
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return hasNext();
			}
			return true;
		}
		public String next() throws Exception {
			if(!st.hasMoreTokens()){
				st = new StringTokenizer(br.readLine().trim());
				return next();
			}
			return st.nextToken();
		}
		public double nextDouble() throws Exception{
			return Double.parseDouble(next());
		}
		public float nextFloat() throws Exception{
			return Float.parseFloat(next());
		}
		public long nextLong() throws Exception{
			return Long.parseLong(next());
		}
		public int nextInt() throws Exception{
			return Integer.parseInt(next());
		}
		public String nextLine() throws Exception{
			return br.readLine();
		}
	}

}


#include <bits/stdc++.h>
//#define int long long
#define hash hashhash
#define X first
#define Y second
#define endl "\n"
#define Mp make_pair
using namespace std;
inline int in(){int32_t x ; scanf("%d",&x) ; return x ; }
inline long long lin(){long long x ; scanf("%lld",&x) ; return x ;}
inline string get(){char ch[2000010] ; scanf("%s",ch) ; return ch;}
inline void read(int *a , int n ) { for (int i = 0 ; i < n ; i ++) a[i] = in() ; }
template <class blank> inline void out(blank x) {cout << x << endl ; exit(0) ;}
template <class blank> inline void smin(blank &a , blank b) {a = min(a , b) ;}
template <class blank> inline void smax(blank &a , blank b) {a = max(a , b) ; }
typedef pair<int , int > pii;
typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vii;
const int maxn  = 1e6 + 10;
const int maxm = 1e6 + 10;
const int maxlg = 21;
const int base = 29;
const int mod = 1e9 + 7;
const ll inf = 2e18 + 10;
const int SQ = 317;
int32_t main()
{
    int n = in()/1000;
    if (n & 1) cout << 1<< endl;
    else cout << 3 << endl;
}


#include <cstdio>
int main() {
  int n;
  scanf("%d", &n);
  n /= 1000;
  puts(n & 1 ? "1" : "3");
  return 0;
}


#include<cstdio>
int main(){
int n;
scanf("%d",&n);
n/=1000;
puts(n&1 ? "1" : "3");
return 0;
}

//hello


#include<cstdio>
int main(){
int n;
scanf("%d",&n);
n/=1000;
puts(n&1 ? "1" : "3");
return 0;
}


#include <cstdio>
int main() {
  int n;
  scanf("%d", &n);
  n /= 1000;
  puts(n & 1 ? "1" : "3");
  return 0;
}
//hellobig_tq


// Problem Link - https://codeforces.com/problemset/problem/676/C
/* By Sanket Singh */
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				emplace_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mp 				map
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define token(str,ch)	(std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;

void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

ll maxBeauty(string s, int k, char ch) {
	int i = 0; //Left pointer
    int j = 0; //Right pointer

    //First move the right pointer forward by k steps.
    //If the character is already ch , do not count a swap and move freely

    int c = 0; //Variable to count the swaps so far

    int ans = 0; //Variable to store the final answer

    for (j = 0; c < k && j < s.size() - 1; j++)
    {
        if (s[j] != ch)
        {
            //If s[j] is not ch then count it as a swap and move forward
            c++;
        }
        if (c == k)
        {
            //If no of swaps has reached k, stop moving j any more forward
            break;
        }
    }

    while (i < j)
    {

        //Move j ahead if next element is ch as it doesn't count as a swap
        while (j < s.size() - 1 && s[j + 1] == ch)
        {
            j++;
        }

        //Store the maximum length of all windows
        int currentLength = j - i + 1;
        ans = max(ans, currentLength);

        //Move left pointer by one to slide the window
        i++;

        //If the char at previous position of left pointer was not ch, then that position must
        //have counted as a swap earlier. Now we have a free swap available.
        //Iterate right pointer forward to use that one free swap
        if (j < s.size() - 1 && s[i - 1] != ch)
        {
            j++;
        }
    }

    return ans;
}

int main(int argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();
	// Write your code here....
	int n, k;
	cin>>n>>k;
	string str;
	cin>>str;
	ll x = maxBeauty(str, k, 'a');
	ll y = maxBeauty(str, k, 'b');
	//log(x, y);
	cout<<max(x, y);
	#ifndef ONLINE_JUDGE
	  clock_t end = clock();
	  cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
	#endif
	return 0;
}


// Problem Link - https://codeforces.com/problemset/problem/676/C
/* By Sanket Singh */
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				emplace_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mp 				map
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define token(str,ch)	(std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;

void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

ll maxBeauty(string str, int k, char ch) {
	ll count = 0;
	ll ans = INT_MIN;
	ll l = 0, r = 0;
	ll temp = 0;
	bool flag = true;
	while(r < str.size()) {
		//log(l, r);
		while(r < str.size() and str[r] == ch) {
			temp++;
			ans = max(ans, temp);
			//log(ans);
			r++;
			flag = false;
		}
		while(r < str.size() and str[r] != ch and count < k) {
			count++;
			temp++;
			ans = max(ans, temp);
			r++;
			flag = false;
		}
		while(l <= r and str[r] != ch and count != 0 and count >= k) {
			//cout<<l<<" "<<r<<endl;
			count -= (str[l] != ch);
			l++;
			temp = r-l;
			//log(temp);
			//count = 0;
		}
		if(flag) {

			r++;
		} else {
			flag = true;
		}
	}
	return ans;
}

int main(int argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();
	// Write your code here....
	int n, k;
	cin>>n>>k;
	string str;
	cin>>str;
	ll x = maxBeauty(str, k, 'a');
	ll y = maxBeauty(str, k, 'b');
	// log(x, y);
	cout<<max(x, y);
	#ifndef ONLINE_JUDGE
	  clock_t end = clock();
	  cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
	#endif
	return 0;
}


// Problem Link - https://codeforces.com/problemset/problem/676/C
/* By Sanket Singh */
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				emplace_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mp 				map
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define token(str,ch)	(std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;

void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

ll maxBeauty(string str, int k, char ch) {
	ll count = 0;
	ll ans = INT_MIN;
	ll l = 0, r = 0;
	ll temp = 0;
	bool flag = true;
	while(r < str.size()) {
		//log(l, r);
		while(r < str.size() and str[r] == ch) {
			temp++;
			ans = max(ans, temp);
			r++;
			flag = false;
		}
		while(r < str.size() and str[r] != ch and count < k) {
			count++;
			temp++;
			ans = max(ans, temp);
			r++;
			flag = false;
		}
		while(l <= r and str[r] != ch and count != 0 and count >= k) {
			count -= (str[l] == ch);
			l++;
			temp = 0;
			count = 0;
		}
		if(flag) {
			r++;
		} else {
			flag = true;
		}
	}
	return ans;
}

int main(int argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();
	// Write your code here....
	int n, k;
	cin>>n>>k;
	string str;
	cin>>str;
	ll x = maxBeauty(str, k, 'a');
	ll y = maxBeauty(str, k, 'b');
	cout<<max(x, y);
	#ifndef ONLINE_JUDGE
	  clock_t end = clock();
	  cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
	#endif
	return 0;
}


// Problem Link - https://codeforces.com/problemset/problem/676/C
/* By Sanket Singh */
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				emplace_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mp 				map
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define token(str,ch)	(std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;

void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

ll maxBeauty(string str, int k, char ch) {
	ll count = 0;
	ll ans = INT_MIN;
	ll l = 0, r = 0;
	ll temp = 0;
	bool flag = true;
	while(r < str.size()) {
		while(r < str.size() and str[r] == ch) {
			ans = max(ans, r-l+1);
			r++;
			flag = false;
		}
		while(r < str.size() and str[r] != ch and count < k) {
			count++;
			ans = max(ans, r-l+1);
			r++;
			flag = false;
		}
		while(l <= r and str[r] != ch and count >= k) {
			if(k == 0) {
				l = ++r;
				break;
			}
			count -= (str[l] != ch);
			l++;
		}
	}
	return ans;
}

int main(int argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();
	// Write your code here....
	int n, k;
	cin>>n>>k;
	string str;
	cin>>str;
	ll x = maxBeauty(str, k, 'a');
	ll y = maxBeauty(str, k, 'b');
	cout<<max(x, y);
	#ifndef ONLINE_JUDGE
	  clock_t end = clock();
	  cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
	#endif
	return 0;
}


// Problem Link - https://codeforces.com/problemset/problem/676/C
/* By Sanket Singh */
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				emplace_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mp 				map
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define token(str,ch)	(std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;

void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

ll maxBeauty(string str, int k, char ch) {
	ll count = 0;
	ll ans = INT_MIN;
	ll l = 0, r = 0;
	ll temp = 0;
	bool flag = true;
	while(r < str.size()) {
		//log(l, r);
		while(r < str.size() and str[r] == ch) {
			//temp++;
			ans = max(ans, r-l+1);
			//log(ans);
			r++;
			flag = false;
		}
		while(r < str.size() and str[r] != ch and count < k) {
			count++;
			//temp++;
			ans = max(ans, r-l+1);
			r++;
			flag = false;
		}
		while(l <= r and str[r] != ch and count >= k) {
			if(k == 0) {
				l = ++r;
				break;
			}
			//cout<<l<<" "<<r<<endl;
			count -= (str[l] != ch);
			l++;
			//temp = r-l;
			//log(temp);
			//count = 0;
		}
		if(flag) {
			r++;
		} else {
			flag = true;
		}
	}
	return ans;
}

int main(int argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();
	// Write your code here....
	int n, k;
	cin>>n>>k;
	string str;
	cin>>str;
	ll x = maxBeauty(str, k, 'a');
	ll y = maxBeauty(str, k, 'b');
	// log(x, y);
	cout<<max(x, y);
	#ifndef ONLINE_JUDGE
	  clock_t end = clock();
	  cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
	#endif
	return 0;
}


// Problem Link - https://codeforces.com/problemset/problem/676/C
/* By Sanket Singh */
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				emplace_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mp 				map
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define token(str,ch)	(std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;)
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;

void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

ll maxBeauty(string s, int k, char ch) {
	int i = 0; //Left pointer
    int j = 0; //Right pointer

    //First move the right pointer forward by k steps.
    //If the character is already ch , do not count a swap and move freely

    int c = 0; //Variable to count the swaps so far

    int ans = 0; //Variable to store the final answer

    for (j = 0; c < k && j < s.size() - 1; j++)
    {
        if (s[j] != ch)
        {
            //If s[j] is not ch then count it as a swap and move forward
            c++;
        }
        if (c == k)
        {
            //If no of swaps has reached k, stop moving j any more forward
            break;
        }
    }

    while (i < j)
    {

        //Move j ahead if next element is ch as it doesn't count as a swap
        while (j < s.size() - 1 && s[j + 1] == ch)
        {
            j++;
        }

        //Store the maximum length of all windows
        int currentLength = j - i + 1;
        ans = max(ans, currentLength);

        //Move left pointer by one to slide the window
        i++;

        //If the char at previous position of left pointer was not ch, then that position must
        //have counted as a swap earlier. Now we have a free swap available.
        //Iterate right pointer forward to use that one free swap
        if (j < s.size() - 1 && s[i - 1] != ch)
        {
            j++;
        }
    }

    return ans;
}

int main(int argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();
	// Write your code here....
	int n, k;
	cin>>n>>k;
	string str;
	cin>>str;
	ll x = maxBeauty(str, k, 'a');
	ll y = maxBeauty(str, k, 'b');
	log(x, y);
	cout<<max(x, y);
	#ifndef ONLINE_JUDGE
	  clock_t end = clock();
	  cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
	#endif
	return 0;
}


// Problem Link -
/* By Sanket Singh */
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				push_back
#define vi              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mp 				make_pair
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define all(n) 			n.begin(),n.end()
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define bitc(n) 		__builtin_popcount(n)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define iter(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
template <typename T> T gcd(T a, T b){if(a%b) return gcd(b,a%b);return b;}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}
vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;

void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
}

ll beauty(string str, ll k, char ch) {
	ll count = 0;
	ll ans = INT_MIN;
	ll l = 0, r = 0;
	while(r < str.size()) {
		while(r < str.size() and str[r] == ch) {
			ans = max(ans, r-l+1);
			r++;
		}
		while(r < str.size() and str[r] != ch and count < k) {
			count++;
			ans = max(ans, r-l+1);
			r++;
		}
		while(l <= r and str[r] != ch and count >= k) {
			if(k == 0) {
				l = ++r;
				break;
			}
			count -= (str[l] != ch);
			l++;
		}
	}
	return ans;
}

int main(int argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();
	// Write your code here....

	ll n, k;
	cin>>n>>k;
	string str;
	cin>>str;
	ll x = beauty(str, k, 'a');
	ll y = beauty(str, k, 'b');
	cout<<max(x, y);
	#ifndef ONLINE_JUDGE
	  clock_t end = clock();
	  cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms";
	#endif
	return 0;
}


//.cpp
#include <bits/stdc++.h>

using namespace std;

int n, m, k, a[100100], a1, l, ans, k1;
char c, pc;

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k1;
    pc = ' ';
    for(int i=0; i<n; i++) {
        cin>>c;
        if(c==pc) a[m]++;
            else a[++m] = 1;
        pc = c;
    }
    l = 0;
    a1 = a[0];
    ans = max(a1, ans);
    k = k1;
    for(int i=1; i<m; i+=2) {
        k -= a[i];
        a1 += a[i]+a[i+1];
        while(k<0) {
            a1 -= a[l++];
            k += a[l];
            a1 -= a[l++];
        }
        ans = max(a1, ans);
    }
    l = 1;
    a1 = a[1];
    ans = max(a1, ans);
    k = k1;
    for(int i=2; i<m; i+=2) {
       k -= a[i];
       a1 += a[i]+a[i+1];
       while(k<0) {
           a1 -= a[l++];
           k += a[l];
           a1 -= a[l++];
       }
       ans = max(a1, ans);
    }
    cout<<ans;
    return 0;
}


//.cpp
#include <bits/stdc++.h>

using namespace std;

int n, m, k, a[100100], od, ev, l, ans;
char c, pc;

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k;
    pc = ' ';
    for(int i=0; i<n; i++) {
        cin>>c;
        if(c==pc) a[m]++;
            else a[++m] = 1;
        pc = c;
    }
    for(int i=0; i<=m; i++) {
        if(i&1) od += a[i]; else ev += a[i];
        while(od>k && ev>k)
            if(l&1) od -= a[l++]; else ev -= a[l++];
        ans = max(od+ev,ans);
    }
    cout<<ans;
    return 0;
}


//.cpp
#include <bits/stdc++.h>

using namespace std;

int n, m, k, a[100100], a1, l, ans, k1;
char c, pc;

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k1;
    pc = ' ';
    for(int i=0; i<n; i++) {
        cin>>c;
        if(c==pc) a[m]++;
            else a[++m] = 1;
        pc = c;
    }
    l = 0;
    a1 = a[0];
    ans = max(a1, ans);
    k = k1;
    for(int i=1; i<=m; i+=2) {
        k -= a[i];
        a1 += a[i]+a[i+1];
        while(k<0) {
            a1 -= a[l++];
            k += a[l];
            a1 -= a[l++];
        }
        ans = max(a1, ans);
    }
    l = 1;
    a1 = a[1];
    ans = max(a1, ans);
    k = k1;
    for(int i=2; i<=m; i+=2) {
       k -= a[i];
       a1 += a[i]+a[i+1];
       while(k<0) {
           a1 -= a[l++];
           k += a[l];
           a1 -= a[l++];
       }
       ans = max(a1, ans);
    }
    cout<<ans;
    return 0;
}


//.cpp
#include <bits/stdc++.h>

using namespace std;

int n, m, k, a[100100], od, ev, l, ans, x;
string s;

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k>>s;
    for(int i=0; i<n; i++) {
        if(s[i]=='a') od++; else ev++;
        while(od>k && ev>k)
            if(s[l++]=='a') od--; else ev--;
        ans = max(od+ev,ans);
    }
    cout<<ans;
    return 0;
}


//.cpp
#include <bits/stdc++.h>

using namespace std;

int n, m, k, a[100100], od, ev, l, ans, x;
string s;

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k>>s;
    for(int i=0; i<n; i++) {
        if(s[i]=='a') od++; else ev++;
        while(od>k && ev>k)
            if(s[l]=='a') od--; else ev--;
        ans = max(od+ev,ans);
    }
    cout<<ans;
    return 0;
}


//.cpp
#include <bits/stdc++.h>

using namespace std;

int n, m, k, a[100100], od, ev, l, ans;
char c, pc;

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k;
    pc = ' ';
    for(int i=0; i<n; i++) {
        cin>>c;
        if(c==pc) a[m]++;
            else a[++m] = 1;
        pc = c;
    }
    for(int i=0; i<=m; i++) {
        if(i&1) od += a[i]; else ev += a[i];
        ans = max(od+ev+(k<0? k : 0),ans);
        while(od>k && ev>k)
            if(l&1) od -= a[l++]; else ev -= a[l++];
    }
    cout<<ans;
    return 0;
}


// By Kishan Radia
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair

using namespace std;
ll f[100005]={0};
vector<ll> v[100005];
ll e[100005]={0};
pair<ll,ll> p[100005];
int main()
{
    ll i,j,n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    i=0;j=0;
    ll c=0;
    ll ans=0;
    while(i<n||j<n){
        ll temp;
        if(j==n){
            //cout<<j<<" "<<i<<endl;
            if(c<=k){
            temp=j-i;
            //cout<<j<<" "<<i<<endl;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='b')c--;
            i++;

            continue;
        }
        temp = j - i;
        if (temp > ans)
          ans = temp;
        if(c<k){
            if(s[j]=='b')c++;
            j++;

        }
        else if(c==k){
            if(s[j]=='b'){
                if(s[i]=='b')c--;
                i++;
                j--;
            }
            else{
                j++;
            }
        }
        else{
            if(s[i]=='b')c--;
            i++;
        }
        //cout<<i<<" "<<j<<endl;
    }
    i=0;j=0;
    c=0;
    //cout<<ans<<endl;
    while(i<n&&j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='a')c--;
            i++;

            continue;
        }
        temp=j-i;
        if(temp>ans)ans=temp;
        if(c<k){
            if(s[j]=='a')c++;
            j++;
        }
        else if(c==k){

            if(s[j]=='a'){
                if(s[i]=='a')c--;
                i++;
                j--;
            }
            else{
                j++;
            }
        }
        else{
            if(s[i]=='a')c--;
            i++;
        }
        //cout<<i<<" "<<j<<endl;
    }

    cout<<ans;
    return 0;
}


// By Kishan Radia
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair

using namespace std;
ll f[100005]={0};
vector<ll> v[100005];
ll e[100005]={0};
pair<ll,ll> p[100005];
int main()
{
    ll i,j,n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    i=0;j=0;
    ll c=0;
    ll ans=0;
    while(i<n||j<n){
        ll temp;
        if(j==n){
            //cout<<j<<" "<<i<<endl;
            if(c<=k){
            temp=j-i;
            //cout<<j<<" "<<i<<endl;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='b')c--;
            i++;

            continue;
        }
        temp = j - i;
        if (temp > ans)
          ans = temp;
        if(c<k){
            if(s[j]=='b')c++;
            j++;

        }
        else if(c==k){
            if(s[j]=='b'){
                if(s[i]=='b')c--;
                i++;
                j--;
            }
            else{
                j++;
            }
        }
        else{
            if(s[i]=='b')c--;
            i++;
        }
        //cout<<i<<" "<<j<<endl;
    }
    i=0;j=0;
    c=0;
    //cout<<ans<<endl;
    while(i<n||j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='a')c--;
            i++;

            continue;
        }
        temp=j-i;
        if(temp>ans)ans=temp;
        if(c<k){
            if(s[j]=='a')c++;
            j++;
        }
        else if(c==k){

            if(s[j]=='a'){
                if(s[i]=='a')c--;
                i++;
                j--;
            }
            else{
                j++;
            }
        }
        else{
            if(s[i]=='a')c--;
            i++;
        }
        //cout<<i<<" "<<j<<endl;
    }

    cout<<ans;
    return 0;
}


// By Kishan Radia
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair

using namespace std;
ll f[100005]={0};
vector<ll> v[100005];
ll e[100005]={0};
pair<ll,ll> p[100005];
int main()
{
    ll i,j,n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    i=0;j=0;
    ll c=0;
    ll ans=0;
    while(i<n||j<n){
        ll temp;
        if(j==n){
            //cout<<j<<" "<<i<<endl;
            if(c<=k){
            temp=j-i;
            //cout<<j<<" "<<i<<endl;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='b')c--;
            i++;

            continue;
        }
        temp = j - i;
        if (temp > ans)
          ans = temp;
        if(c<k){
            if(s[j]=='b')c++;
            j++;

        }
        else if(c==k){
            if(s[j]=='b'){
                if(s[i]=='b')c--;
                i++;
                if(j>i)j--;
            }
            else{
                j++;
            }
        }
        else{
            if(s[i]=='b')c--;
            i++;
        }
        //cout<<i<<" "<<j<<endl;
    }
    i=0;j=0;
    c=0;
    //cout<<ans<<endl;
    while(i<n||j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='a')c--;
            i++;
            continue;
        }
        temp=j-i;
        if(temp>ans)ans=temp;
        if(c<k){
            if(s[j]=='a')c++;
            j++;
        }
        else if(c==k){

            if(s[j]=='a'){
                if(s[i]=='a')c--;
                i++;
                if(j>i)j--;
            }
            else{
                j++;
            }
        }
        else{
            if(s[i]=='a')c--;
            i++;
        }
        //cout<<i<<" "<<j<<endl;
    }

    cout<<ans;
    return 0;
}


// By Kishan Radia
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair

using namespace std;
ll f[100005]={0};
vector<ll> v[100005];
ll e[100005]={0};
pair<ll,ll> p[100005];
int main()
{
    ll i,j,n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    i=0;j=0;
    ll c=0;
    ll ans=0;
    while(i<n&&j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='b')c--;
            i++;

            continue;
        }
        if(c<k){
            if(s[j]=='b')c++;
            j++;
            if(j<n)
            temp=j-i+1;
            else temp=j-i;
            if(temp>ans)ans=temp;
        }
        else if(c==k){

            if(s[j]=='b'){
                if(s[i]=='b')c--;
                i++;
                j--;
                temp=j-i+1;
                if(temp>ans)ans=temp;
            }
            else{
                temp=j-i+1;
                if(temp>ans)ans=temp;
                j++;

            }

        }
        else{
            if(s[i]=='b')c--;
            i++;
        }
    }
    i=0;j=0;
    while(i<n&&j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='a')c--;
            i++;

            continue;
        }
        if(c<k){
            if(s[j]=='a')c++;
            j++;
            if(j<n)
            temp=j-i+1;
            else temp=j-i;
            if(temp>ans)ans=temp;
        }
        else if(c==k){

            if(s[j]=='a'){
                if(s[i]=='a')c--;
                i++;
                j--;
                temp=j-i+1;
                if(temp>ans)ans=temp;
            }
            else{
                temp=j-i+1;
                if(temp>ans)ans=temp;
                j++;

            }

        }
        else{
            if(s[i]=='a')c--;
            i++;
        }
    }

    cout<<ans;
    return 0;
}


// By Kishan Radia
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair

using namespace std;
ll f[100005]={0};
vector<ll> v[100005];
ll e[100005]={0};
pair<ll,ll> p[100005];
int main()
{
    ll i,j,n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    i=0;j=0;
    ll c=0;
    ll ans=0;
    while(i<n&&j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='b')c--;
            i++;

            continue;
        }
        if(c<k){
            if(s[j]=='b')c++;
            j++;
            if(j<n)
            temp=j-i+1;
            else temp=j-i;
            if(temp>ans)ans=temp;
        }
        else if(c==k){

            if(s[j]=='b'){
                if(s[i]=='b')c--;
                i++;
                j--;
                temp=j-i+1;
                if(temp>ans)ans=temp;
            }
            else{
                temp=j-i+1;
                if(temp>ans)ans=temp;
                j++;

            }

        }
        else{
            if(s[i]=='b')c--;
            i++;
        }
    }
    i=0;j=0;
    c=0;
    //cout<<ans<<endl;
    while(i<n&&j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='a')c--;
            i++;

            continue;
        }
        if(c<k){
            if(s[j]=='a')c++;
            j++;
            if(j<n)
            temp=j-i+1;
            else temp=j-i;
            if(temp>ans)ans=temp;
        }
        else if(c==k){

            if(s[j]=='a'){
                if(s[i]=='a')c--;
                i++;
                j--;
                temp=j-i+1;
                if(temp>ans)ans=temp;
            }
            else{
                temp=j-i+1;
                if(temp>ans)ans=temp;
                j++;

            }

        }
        else{
            if(s[i]=='a')c--;
            i++;
        }
        //cout<<i<<" "<<j<<endl;
    }

    cout<<ans;
    return 0;
}


// By Kishan Radia
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    ll c=0;
    ll i=0,j=0,temp,ans=0;
    while(i<n||j<n){
        if(j==n){
            temp=j-i;
            if(c<=k){
                if(temp>ans)ans=temp;
            }
            if(s[i]=='b')c--;
            i++;
            continue;
        }

        if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
        }
        if(s[j]=='b'){
            c++;
            j++;
        }
        else{
            j++;
        }
        if(c>k){
            if(s[i]=='b')c--;
            i++;
        }

    }

    i=0;j=0;c=0;

    while (i < n || j < n) {
      if (j == n) {
        temp = j - i;
        if (c <= k) {
          if (temp > ans)
            ans = temp;
        }
        if (s[i] == 'a')
          c--;
        i++;
        continue;
      }

      if (c <= k) {
        temp = j - i;
        if (temp > ans)
          ans = temp;
      }
      if (s[j] == 'a') {
        c++;
        j++;
      }
      else j++;
      if (c > k) {
        if (s[i] == 'a')
          c--;
        i++;
      }
    }

    cout<<ans;
    return 0;
}


// By Kishan Radia
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair

using namespace std;
ll f[100005]={0};
vector<ll> v[100005];
ll e[100005]={0};
pair<ll,ll> p[100005];
int main()
{
    ll i,j,n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    i=0;j=0;
    ll c=0;
    ll ans=0;
    while(i<n&&j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='b')c--;
            i++;

            continue;
        }
        if(c<k){
            if(s[j]=='b')c++;
            j++;
            if(j<n)
            temp=j-i+1;
            else temp=j-i;
            if(temp>ans)ans=temp;
        }
        else if(c==k){

            if(s[j]=='b'){
                if(s[i]=='b')c--;
                i++;
                j--;
                temp=j-i+1;
                if(temp>ans)ans=temp;
            }
            else{
                temp=j-i+1;
                if(temp>ans)ans=temp;
                j++;

            }

        }
        else{
            if(s[i]=='b')c--;
            i++;
        }
    }
    cout<<ans;
    return 0;
}


// By Kishan Radia
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair

using namespace std;
ll f[100005]={0};
vector<ll> v[100005];
ll e[100005]={0};
pair<ll,ll> p[100005];
int main()
{
    ll i,j,n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    i=0;j=0;
    ll c=0;
    ll ans=0;
    while(i<n&&j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='b')c--;
            i++;

            continue;
        }
          temp = j - i;
        if (temp > ans)
          ans = temp;
        if(c<k){
            if(s[j]=='b')c++;
            j++;

        }
        else if(c==k){
            if(s[j]=='b'){
                if(s[i]=='b')c--;
                i++;
                j--;
            }
            else{
                j++;
            }
        }
        else{
            if(s[i]=='b')c--;
            i++;
        }
    }
    i=0;j=0;
    c=0;
    //cout<<ans<<endl;
    while(i<n&&j<n){
        ll temp;
        if(j==n){
            if(c<=k){
            temp=j-i;
            if(temp>ans)ans=temp;
            }
            if(s[i]=='a')c--;
            i++;

            continue;
        }
        temp=j-i;
        if(temp>ans)ans=temp;
        if(c<k){
            if(s[j]=='a')c++;
            j++;
        }
        else if(c==k){

            if(s[j]=='a'){
                if(s[i]=='a')c--;
                i++;
                j--;
            }
            else{
                j++;
            }
        }
        else{
            if(s[i]=='a')c--;
            i++;
        }
        //cout<<i<<" "<<j<<endl;
    }

    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	vector<vector<ll>> dp(n,vector<ll>(2,0));
	if(s[0]=='a')dp[0][0]=1;
	else dp[0][1]=1;
	for(ll i=1;i<n;i++)
	{
		if(s[i]=='a')dp[i][0]=dp[i-1][0]+1,dp[i][1]=dp[i-1][1];
		else dp[i][0]=dp[i-1][0],dp[i][1]=dp[i-1][1]+1;
	}
	ll mx=-1;
	for(ll i=0;i<n;i++)
	{
		ll ans=-1;
		if(s[i]=='a')
		{
		ll lo=i,hi=n-1;
		while(lo<=hi)
		{
			ll mid=(lo+hi)/2;
			ll count=dp[mid][1]-dp[i][0];
			if(count<=k)
			{
				ans=mid-i+1;
				lo=mid+1;
			}
			else hi=mid-1;
			}
		}
		else{
			ll lo=i,hi=n-1;
		while(lo<=hi)
		{
			ll mid=(lo+hi)/2;
			ll count=dp[mid][0]-dp[i][1];
			if(count<=k)
			{
				ans=mid-i+1;
				lo=mid+1;
			}
			else hi=mid-1;
			}
		}
		mx=max(mx,ans);
	}
	cout<<mx<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef int ll;
ll ans(string s,ll lo,ll hi,ll k,vector<vector<ll>> dp)
{
	ll counta=dp[hi][0]-dp[lo][0];
	if(s[lo]=='a')counta++;
	ll countb=dp[hi][1]-dp[lo][1];
	if(s[lo]=='b')countb++;
	if(min(counta,countb)<=k)return hi-lo+1;
	ll x,y;
	x=ans(s,lo,hi-1,k,dp);
	y=ans(s,lo+1,hi,k,dp);

	return max(x,y);
}
int main()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	vector<vector<ll>> dp(n,vector<ll>(2,0));
	if(s[0]=='a')dp[0][0]=1;
	else dp[0][1]=1;
	for(ll i=1;i<n;i++)
	{
		if(s[i]=='a')dp[i][0]=dp[i-1][0]+1,dp[i][1]=dp[i-1][1];
		else dp[i][0]=dp[i-1][0],dp[i][1]=dp[i-1][1]+1;
	}
	cout<<ans(s,0,s.length()-1,k,dp)<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m;
string s;
ll check(char x)
{
    ll i,j=0,cnt=0,ans=0;
    for(i=0; i<n; i++)
    {
        if(s[i]==x)
            cnt++;
        if(cnt>m)
        {
            while(cnt>m)
            {
                if(s[j++]==x)
                    cnt--;
            }
        }
        ans=max(ans,i-j+1);
    }
    return ans;
}
int main()
{
	cin>>n>>m;
	cin>>s;
	check('a');
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m;
string s;
ll check(char x)
{
    ll i,j=0,cnt=0,ans=0;
    for(i=0; i<n; i++)
    {
        if(s[i]==x)
            cnt++;
        if(cnt>m)
        {
            while(cnt>m)
            {
                if(s[j++]==x)
                    cnt--;
            }
        }
        ans=max(ans,i-j+1);
    }
    return ans;
}
int main()
{
	cin>>n>>m;
	cin>>s;
	cout<<max(check('a'),check('b'))<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll ans(string s,ll lo,ll hi,ll k,vector<vector<ll>> dp)
{
	ll counta=dp[hi][0]-dp[lo][0];
	if(s[lo]=='a')counta++;
	ll countb=dp[hi][1]-dp[lo][1];
	if(s[lo]=='b')countb++;
	if(min(counta,countb)<=k)return hi-lo+1;
	ll x,y;
	x=ans(s,lo,hi-1,k,dp);
	y=ans(s,lo+1,hi,k,dp);

	return max(x,y);
}
int main()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	vector<vector<ll>> dp(n,vector<ll>(2,0));
	if(s[0]=='a')dp[0][0]=1;
	else dp[0][1]=1;
	for(ll i=1;i<n;i++)
	{
		if(s[i]=='a')dp[i][0]=dp[i-1][0]+1,dp[i][1]=dp[i-1][1];
		else dp[i][0]=dp[i-1][0],dp[i][1]=dp[i-1][1]+1;
	}
	cout<<ans(s,0,s.length()-1,k,dp)<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	if(k==0)
	{
		ll ans=-1;
		char c=s[0];
		ll count=1;
		for(ll i=1;i<n-1;i++)
		{
			if(s[i]==c)
			count++;
			else {
				ans=max(ans,count);
				count=1;
			}
		}
		ans=max(ans,count);
		cout<<ans<<endl;
		return 0;
	}
	ll k1=0;
	ll ans=-1;
	ll prev=0;
	//suppose a
	ll maxLength=0;
	vector<ll> temp;
	for(ll i=0;i<n;i++)
	{
		if(s[i]=='a')
		maxLength++;
		if(s[i]=='b'&&maxLength!=0)
		{
			if(k1<k)
			{
				temp.push_back(maxLength+1);
				maxLength++;
				k1++;
			}
			else{
				ans=max(ans,maxLength);
				k1--;
				maxLength-=(temp[0]-prev);
				prev=temp[0];
				temp.erase(temp.begin());
			}
		}
	}
	ans=max(ans,maxLength);
	//suppose b
	maxLength=0;
	temp.clear();
	prev=0;
	k1=0;
	for(ll i=0;i<n;i++)
	{
		if(s[i]=='b')
		maxLength++;
		if(s[i]=='a'&&maxLength!=0)
		{

			if(k1<k)
			{
				temp.push_back(maxLength+1);
				maxLength++;
				k1++;
			}
			else{
				ans=max(ans,maxLength);
				k1--;
				maxLength-=(temp[0]-prev);
				prev=temp[0];
				temp.erase(temp.begin());
			}
		}
	}
	ans=max(ans,maxLength);
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	if(k==0)
	{
		ll ans=-1;
		char c=s[0];
		ll count=1;
		for(ll i=1;i<n-1;i++)
		{
			if(s[i]==c)
			count++;
			else {
				ans=max(ans,count);
				count=1;
			}
		}
		ans=max(ans,count);
		cout<<ans<<endl;
		return 0;
	}
	ll k1=0;
	ll ans=-1,prev=-1;
	//suppose a
	ll maxLength=0;
	vector<ll> temp;
	for(ll i=0;i<n;i++)
	{
		if(s[i]=='a')
		maxLength++;
		if(s[i]=='b'&&maxLength!=0)
		{

			if(k1<k)
			{
				temp.push_back(maxLength);
				maxLength++;
				k1++;
			}
			else{
				ans=max(ans,maxLength);
				k1--;
				maxLength-=temp[0];
				temp.erase(temp.begin());
				maxLength--;
			}
		}
	}
	ans=max(ans,maxLength);
	//suppose b
	maxLength=0;
	temp.clear();
	k1=0;
	for(ll i=0;i<n;i++)
	{
		if(s[i]=='b')
		maxLength++;
		if(s[i]=='a'&&maxLength!=0)
		{

			if(k1<k)
			{
				temp.push_back(maxLength);
				maxLength++;
				k1++;
			}
			else{
				ans=max(ans,maxLength);
				k1--;
				maxLength-=temp[0];
				temp.erase(temp.begin());
				maxLength--;
			}
		}
	}
	ans=max(ans,maxLength);
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
map<pair<ll,ll>,ll> mp;
ll ans(string s,ll lo,ll hi,ll k,vector<vector<ll>> dp)
{
	ll counta=dp[hi][0]-dp[lo][0];
	if(s[lo]=='a')counta++;
	ll countb=dp[hi][1]-dp[lo][1];
	if(s[lo]=='b')countb++;
	if(min(counta,countb)<=k)return hi-lo+1;
	ll x,y;
	if(mp[{lo,hi-1}]!=0)x=mp[{lo,hi-1}];
	else {
		mp[{lo,hi-1}]=ans(s,lo,hi-1,k,dp);
		x=mp[{lo,hi-1}];
		}
	if(mp[{lo+1,hi}]!=0)y=mp[{lo+1,hi}];
	else{
		mp[{lo+1,hi}]=ans(s,lo+1,hi,k,dp);
		y=mp[{lo+1,hi}];
	}
	return max(x,y);
}
int main()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	vector<vector<ll>> dp(n,vector<ll>(2,0));
	if(s[0]=='a')dp[0][0]=1;
	else dp[0][1]=1;
	for(ll i=1;i<n;i++)
	{
		if(s[i]=='a')dp[i][0]=dp[i-1][0]+1,dp[i][1]=dp[i-1][1];
		else dp[i][0]=dp[i-1][0],dp[i][1]=dp[i-1][1]+1;
	}
	cout<<ans(s,0,s.length()-1,k,dp);
}


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {

        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();
        if(index==0&&c1[index]==0)
            index--;

        if(maxi<(i-index))
            maxi=i-index;
   }
    ////second part
    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {
            n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();

          if(index==0&&c2[index]==0)
            index--;

        if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {

        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();

        if(index==0)
            index--;
 if(s[0]=='b'&&index==-1)
            index++;
        if(maxi<(i-index))
            maxi=i-index;
   }
    ////second part

    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {

            n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();

        if(index==0)
            index--;
        if(s[0]=='a'&&index==-1)
            index++;
        if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {

        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();
        if(index==0&&c1[index]-b<0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
    ////second part
    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {
            n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();

          if(index==0&&c2[index]-b<0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {

        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();
        if(index==0&&c1[i]-b==0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
    ////second part
    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {
            n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();

          if(index==0&&c2[i]-b==0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {

        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();
        if(index==0&&c1[index]-b<=0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
    ////second part
    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {
            n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();

          if(index==0&&c2[index]-b<=0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {
         if(s[i]=='b')
            num=lower_bound (c1.begin(), c1.end(),c1[i]-(b-1));
            else
        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();

        if(index==0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
    ////second part
    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {
       if(s[i]=='a')
        n=lower_bound (c2.begin(), c2.end(),c2[i]-(b-1));
        else
            n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();

        if(index==0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {
         if(s[i]=='b')
            num=lower_bound (c1.begin(), c1.end(),c1[i]-(b-1));
            else
        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();

        if(index==0&&s[0]=='a')
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
    ////second part
    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {
       if(s[i]=='a')
        n=lower_bound (c2.begin(), c2.end(),c2[i]-(b-1));
        else
            n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();

        if(index==0&&s[0]=='b')
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {

        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();
    if(c1[i]-b<=0)
    {
        if(maxi<i+1)
            maxi=i+1;
    }
    else
          if(maxi<(i-index))
            maxi=i-index;
        /*if(index==0)
            index--;
 if(s[0]=='b'&&index==-1)
            index++;*/

   }
    ////second part

    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {

            n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();

       if(c2[i]-b<=0)
    {
        if(maxi<i+1)
            maxi=i+1;
    }
    else
          if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {

        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();
        if(index==0&&c1[i]-b==0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
    ////second part
    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {
            n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();

          if(index==0&&c1[i]-b==0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
  #define ll long long
        using namespace std;
        /*
        //setpression
        double w;
                double x = modf(a,&w);
                x  = roundf(x * 100000.0)/100000.0;
                a = w+x;
        */
 long long fast_pow(unsigned long long a,unsigned long long n)
    {
        unsigned long long result = 1;
        unsigned long long power = n;
         unsigned long long value = a;
        while(power>0)
        {
            if(power&1)
                {result = result*value;
                result = result%1000000007;}
            value = value*value;
            value = value%1000000007;
            power /= 2;
            //power >>= 1;
        }
        return result%1000000007;
    }
  ////////////////////////////////////////////////////
  bool test[100];

        int main()
        {

            ios_base::sync_with_stdio(false);
            //cin.tie(nullptr);
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	////////////////////////////////////////////////////
   ll a,b;
   cin>>a>>b;
   string s;
   cin>>s;
   vector<ll>c1,c2;
   ////// first part
   ll counter=0,maxi=LONG_LONG_MIN,counter1=0;
   for(int i=0;i<a;i++)
   {
       if(s[i]=='b')
        counter++;
        c1.push_back(counter);
   }
   vector<ll>::iterator num;
    for(int i=a-1;i>=0;i--)
   {
        num=lower_bound (c1.begin(), c1.end(),c1[i]-b);
        ll index=num-c1.begin();
        if(index==0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
    ////second part
    for(int i=0;i<a;i++)
   {
       if(s[i]=='a')
        counter1++;
        c2.push_back(counter1);
   }
   vector<ll>::iterator n;
    for(int i=a-1;i>=0;i--)
   {
        n=lower_bound (c2.begin(), c2.end(),c2[i]-b);
        ll index=n-c2.begin();
        if(index==0)
            index--;
        if(maxi<(i-index))
            maxi=i-index;
   }
   cout<<maxi;
            return 0;
       }


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
	ll n,k,max=1;
	cin>>n>>k;
	string s;
	cin>>s;
	ll j=-1,l=-1,a[n],b[n];

	for(ll i=0;i<n;i++)
	{
		if(s[i]=='a')
		{
			j++;
			a[j]=i;
		}
		else
		{
			l++;
			b[l]=i;
		}
	}
	if(j==-1||l==-1||j<k||l<k)
	{
		cout<<n;
		return 0;
	}
	if(j>=0){
	for(ll i=0;i<=j-k+1;i++)
	{
		if(i==0)
		{
			if(k-1>=j)
			max=n;
			else
			{
				ll z=a[k]-1;
				if(max<z)
				max=z;
			}
		}
		else if(i==j-k+1)
		{
			ll z=n-a[i-1];
			if(max<z)
			max=z;
		}
		else
		{
			ll z=a[i+k]-a[i-1]-1;
			if(max<z)
			max=z;
		}
	}
}
if(l>=0){

	for(ll i=0;i<=l-k+1;i++)
	{
		if(i==0)
		{
			ll y=k-1;
			if(k-1>=l)
			max=n;
			else
			{
				ll z=b[k]-1;
				if(max<z)
				max=z;
			}
		}
		else if(i==l-k+1)
		{
			ll z=n-b[i-1];
			if(max<z)
			max=z;
		}
		else
		{
			ll z=b[i+k]-b[i-1]-1;
			if(max<z)
			max=z;
		}
	}
}
	cout<<max;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
	ll n,k,max=1;
	cin>>n>>k;
	string s;
	cin>>s;
	ll j=-1,l=-1,a[n],b[n];
	if(j==-1||l==-1)
	{
		cout<<n;
		return 0;
	}
	for(ll i=0;i<n;i++)
	{
		if(s[i]=='a')
		{
			j++;
			a[j]=i;
		}
		else
		{
			l++;
			b[l]=i;
		}
	}
	for(ll i=0;i<=j-k+1,j>=0;i++)
	{
		if(i==0)
		{
			ll y=k-1;
			if(k-1==j)
			max=n;
			else
			{
				ll z=a[k]-1;
				if(max<z)
				max=z;
			}
		}
		else if(i==j-k+1)
		{
			ll z=n-a[i-1]-1;
			if(max<z)
			max=z;
		}
		else
		{
			ll z=a[i+k]-a[i-1]-1;
			if(max<z)
			max=z;
		}
	}
	for(ll i=0;i<=l-k+1,l>=0;i++)
	{
		if(i==0)
		{
			ll y=k-1;
			if(k-1==l)
			max=n;
			else
			{
				ll z=b[k]-1;
				if(max<z)
				max=z;
			}
		}
		else if(i==l-k+1)
		{
			ll z=n-b[i-1]-1;
			if(max<z)
			max=z;
		}
		else
		{
			ll z=b[i+k]-b[i-1]-1;
			if(max<z)
			max=z;
		}
	}
	cout<<max;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
	ll n,k,max=1;
	cin>>n>>k;
	string s;
	cin>>s;
	ll l=0,m=0;
	ll i;
	for(ll j=0;j<n;j++)
	{
		i=j-1;
		ll y=1;
		l=0;m=0;
		while(y&&i<n-1)
		{
			i++;
			if(s[i]=='a')
			l++;
			else
			m++;
			if((l>k&&m>k)||i==n-1)
			{
				if(i==n-1&&l<=k&&m<=k&&l+m>max)
				max=l+m;
				else
				{
					if(l+m-1>max)
					max=l+m-1;
				}
				break;
				y=0;
			}
		}
	}
	cout<<max;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
	ll n,k,max=1;
	cin>>n>>k;
	string s;
	cin>>s;
	ll l=0,m=0;
	ll i;
	for(ll j=0;j<n;j++)
	{
		i=j-1;
		ll y=1;
		l=0;m=0;
		while(y&&i<n-1)
		{
			i++;
			if(s[i]=='a')
			l++;
			else
			m++;
			if((l>k&&m>k)||i==n-1)
			{
				//cout<<l<<m;
				if(i==n-1&&(l<=k||m<=k)&&l+m>max)
				max=l+m;
				else
				{
					if(l+m-1>max)
					max=l+m-1;
				}
				break;
				y=0;
			}
		}
		if(i==n-1&&l>k&&m>k)
		break;

	}
	cout<<max;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
	ll n,k,max=1;
	cin>>n>>k;
	string s;
	cin>>s;
	ll j=-1,l=-1,a[n],b[n];

	for(ll i=0;i<n;i++)
	{
		if(s[i]=='a')
		{
			j++;
			a[j]=i;
		}
		else
		{
			l++;
			b[l]=i;
		}
	}
	if(j==-1||l==-1||j<k||l<k)
	{
		cout<<n;
		return 0;
	}
	if(j>=0){
	for(ll i=0;i<=j-k+1;i++)
	{
		if(i==0)
		{
			if(k-1>=j)
			max=n;
			else
			{
				ll z=a[k];
				if(max<z)
				max=z;
			}
		}
		else if(i==j-k+1)
		{
			ll z=n-a[i-1]-1;
			if(max<z)
			max=z;
		}
		else
		{
			ll z=a[i+k]-a[i-1]-1;
			if(max<z)
			max=z;
		}
	}
}
if(l>=0){

	for(ll i=0;i<=l-k+1;i++)
	{
		if(i==0)
		{
			if(k-1>=l)
			max=n;
			else
			{
				ll z=b[k];
				if(max<z)
				max=z;
			}
		}
		else if(i==l-k+1)
		{
			ll z=n-b[i-1]-1;
			if(max<z)
			max=z;
		}
		else
		{
			ll z=b[i+k]-b[i-1]-1;
			if(max<z)
			max=z;
		}
	}
}
	cout<<max;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
	ll n,k,max=1;
	cin>>n>>k;
	string s;
	cin>>s;
	ll j=-1,l=-1,a[n],b[n];

	for(ll i=0;i<n;i++)
	{
		if(s[i]=='a')
		{
			j++;
			a[j]=i;
		}
		else
		{
			l++;
			b[l]=i;
		}
	}
	if(j==-1||l==-1||j<k||l<k)
	{
		cout<<n;
		return 0;
	}
	if(j>=0){
	for(ll i=0;i<=j-k+1;i++)
	{
		if(i==0)
		{
			if(k-1>=j)
			max=n;
			else
			{
				ll z=a[k]-1;
				if(max<z)
				max=z;
			}
		}
		else if(i==j-k+1)
		{
			ll z=n-a[i-1]-1;
			if(max<z)
			max=z;
		}
		else
		{
			ll z=a[i+k]-a[i-1]-1;
			if(max<z)
			max=z;
		}
	}
}
if(l>=0){

	for(ll i=0;i<=l-k+1;i++)
	{
		if(i==0)
		{
			ll y=k-1;
			if(k-1>=l)
			max=n;
			else
			{
				ll z=b[k]-1;
				if(max<z)
				max=z;
			}
		}
		else if(i==l-k+1)
		{
			ll z=n-b[i-1]-1;
			if(max<z)
			max=z;
		}
		else
		{
			ll z=b[i+k]-b[i-1]-1;
			if(max<z)
			max=z;
		}
	}
}
	cout<<max;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
	ll n,k,max=1;
	cin>>n>>k;
	string s;
	cin>>s;
	ll j=-1,l=-1,a[n],b[n];

	for(ll i=0;i<n;i++)
	{
		if(s[i]=='a')
		{
			j++;
			a[j]=i;
		}
		else
		{
			l++;
			b[l]=i;
		}
	}
	if(j==-1||l==-1||j<=k||l<=k)
	{
		cout<<n;
		return 0;
	}
	if(j>=0){
	for(ll i=0;i<=j-k+1;i++)
	{
		if(i==0)
		{
			if(k-1>=j)
			max=n;
			else
			{
				ll z=a[k]-1;
				if(max<z)
				max=z;
			}
		}
		else if(i==j-k+1)
		{
			ll z=n-a[i-1]-1;
			if(max<z)
			max=z;
		}
		else
		{
			ll z=a[i+k]-a[i-1]-1;
			if(max<z)
			max=z;
		}
	}
}
if(l>=0){

	for(ll i=0;i<=l-k+1;i++)
	{
		if(i==0)
		{
			ll y=k-1;
			if(k-1>=l)
			max=n;
			else
			{
				ll z=b[k]-1;
				if(max<z)
				max=z;
			}
		}
		else if(i==l-k+1)
		{
			ll z=n-b[i-1]-1;
			if(max<z)
			max=z;
		}
		else
		{
			ll z=b[i+k]-b[i-1]-1;
			if(max<z)
			max=z;
		}
	}
}
	cout<<max;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
	ll n,k,max=1;
	cin>>n>>k;
	string s;
	cin>>s;
	ll l=0,m=0;
	ll i;
	for(ll j=0;j<n;j++)
	{
		i=j-1;
		ll y=1;
		l=0;m=0;
		while(y&&i<n-1)
		{
			i++;
			if(s[i]=='a')
			l++;
			else
			m++;
			if((l>k&&m>k)||i==n-1)
			{
				//cout<<l<<m;
				if(i==n-1&&(l<=k||m<=k)&&l+m>max)
				max=l+m;
				else
				{
					if(l+m-1>max)
					max=l+m-1;
				}
				break;
				y=0;
			}
		}
	}
	cout<<max;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
	ll n,k,max=1;
	cin>>n>>k;
	string s;
	cin>>s;
	ll l=0,m=0;
	for(ll i=0;i<n;i++)
	{
		ll y=1;
		while(y)
		{
			i++;
			if(s[i]=='a')
			l++;
			else
			m++;
			if(l>=k&&m>=k)
			{
				if(l+m>max)
				max=l+m;
				break;
				y=0;
			}
		}
	}
	cout<<max;

return 0;
}


#include <iostream>

using namespace std;
bool arr[100001];
int main()
{
    int n,k,kc,i,j,aa=0,ab=0;
    char c;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='b')
            arr[i]=1;
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        if(j<i)
            j=i;
        while(kc&&j<n)
        {
            if(arr[j]&&kc)
                kc--;
            j++;
        }
        while(j<n&&!arr[j])
            j++;
        if(j-i>aa)
            aa=j-i;
        if(j==n)
            break;
        if(arr[i])
        {
            while(arr[i]&&i<j)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            if(kc)
                i--;
        }
    }
    kc=k;
    for(i=0,j=0;i<n;i++)
    {
        if(j<i)
            j=i;
        while(kc&&j<n)
        {
            if(!arr[j]&&kc)
                kc--;
            j++;
        }
        while(j<n&&arr[j])
            j++;
        if(j-i>ab)
            ab=j-i;
        if(j==n)
            break;
        if(!arr[i])
        {
            while(!arr[i]&&i<j)
            {
                if(kc<k)
                    kc++;
                i++;
            }
            if(kc)
                i--;
        }
    }
    if(aa>ab)
        cout<<aa;
    else
        cout<<ab;
    return 0;
}
/*char c[100001];
int solve(int n,int k,char a)
{
    int i,j=0,kc=k;
    for(i=0;i<n;i++)
    {
        while(j<=i&&k<0)
        {
            if()
        }
    }
}
int main()
{
    int n,k;
    cin>>n>>k>>c;

    return 0;
}*/