#include<bits/stdc++.h>
using namespace std;
const int maxn = 100007;
int n,k;
char str[maxn];
vector<int> vi;
int main()
{
    //freopen("in.txt","r",stdin);
    scanf("%d %d",&n,&k);
    scanf("%s",str);
    int len = strlen(str);
    char bef = str[0],aft;
    int tot = 1;
    int sum = 0;
    for(int i = 1;i < len;i++)
    {
        aft = str[i];
        if(aft == bef)tot++;
        else{
            vi.push_back(tot);
            sum += tot;
            tot = 1;
            bef = aft;
        }
    }
    vi.push_back(tot);
    sum += tot;
    int veclen = vi.size();
//    for(int i = 0;i < veclen;i++)
//    {
//        printf("%d ",vi[i]);
//    }

    bool first;
    if(str[0] == '1')first = true;
    else first = false;
    int value = 0;
    int ans;
    if(veclen % 2){
        if(first){
            //printf("1 true This,veclen =%d\n",veclen);
            if(k * 2 +1>= veclen){
                printf("%d\n",sum);
            }
            else//奇数，第一个正确
            {
                value = 0;
                ans = 0;
                int i,j = 0;
                for(i = 0;i <= 2*k;i++)value+=vi[i];
                ans = value;
                while(i < vi.size()){
                    value += vi[i++];
                    value += vi[i++];
                    value -= vi[j++];
                    value -= vi[j++];
                    if(ans < value)ans = value;
                }
                printf("%d\n",ans);
            }
        }
        else{
            //printf("1 false This,veclen = %d\n",veclen);
            if(k * 2 - 1 >= veclen)printf("%d\n",sum);
            else{//奇数，第一个错误
                vi.push_back(0);
                value = 0;
                ans = 0;
                int i,j = -1;
                for(i=0;i <= 2*k - 1;i++)value += vi[i];
                ans = value;
                while(i < vi.size()){
                    value += vi[i++];
                    value += vi[i++];
                    if(j >= 0)value -= vi[j++];
                    else j++;
                    value -= vi[j++];
                    if(ans < value)ans = value;
                }
                printf("%d\n",ans);
            }
        }
    }
    else{
        if(k * 2 >= veclen){
            printf("%d\n",sum);
        }
        else{//偶数
            if(first){
                //printf("2 true This,veclen = %d\n",veclen);
                vi.push_back(0);
                value = 0;
                ans = 0;
                int i,j = 0;
                for(i = 0;i <= 2*k;i++)value += vi[i];
                ans = value;
                while(i < vi.size()){
                    value += vi[i++];
                    value += vi[i++];
                    value -= vi[j++];
                    value -= vi[j++];
                    if(ans < value)ans = value;
                }
                printf("%d\n",ans);
            }
            else{
                //printf("2 false This,veclen = %d\n",veclen);
                value = 0;
                ans = 0;
                int i,j = -1;
                for(i=0;i <= 2*k - 1;i++)value += vi[i];
                ans = value;
                while(i < vi.size()){
                    value += vi[i++];
                    value += vi[i++];
                    if(j >= 0)value -= vi[j++];
                    else j++;
                    value -= vi[j++];
                    if(ans < value)ans = value;
                }
                printf("%d\n",ans);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1020