/*input
5 1
00010
*/

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb          push_back
#define pp          pop_back
#define nl          cout << "\n"
#define MIN(con)    (*min_element(ALL(con)))
#define MAX(con)    (*max_element(ALL(con)))
#define NX(cont)    next_permutation(ALL(cont))
#define PX(cont)    prev_permutation(ALL(cont))
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define all(c)      c.begin(),c.end()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sp          cout << " "
#define ifalse      ios_base::sync_with_stdio(false),cin.tie(NULL)
#define debug(x)    cout << #x << " = " << x << "\n";

using ll = long long;
using ld = long double;
 
template <typename T> T GCD(T a, T b) { ll t; while(a){ t=a; a=b%a; b=t; } return b; }
template <typename T> T LCM(T a, T b) { return (a*b) / GCD(a, b); }
template <typename T> string toString(T a) { return to_string(a); }
template <typename T> void toInt(string s, T &x) { stringstream str(s); str >> x; }

ll add(ll x, ll y, ll MOD) { x += y; if(x >= MOD) x -= MOD; return x; }
ll sub(ll x, ll y, ll MOD) { x -= y; if(x < 0) x += MOD; return x; }
ll mul(ll x, ll y, ll MOD) { return ((x % MOD) * (y % MOD)) % MOD; }

ll powr(ll a, ll b, ll MOD) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a, MOD);
    a = mul(a, a, MOD);
    b >>= 1;
  }
  return x;
}

ll inv(ll a, ll MOD) { return powr(a, MOD-2, MOD); }
const ll INF =  1e18;
const int SINF = 1e9;
const ll MOD = 1e9 + 7;

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/************************************START***************************************/
const int N = 100005;
vector < int > v;
map < string, int > mp;
int n1;

int func(int n, int k, int flag)
{
  if(n <= 0 or flag == 2) {
    return 0;
  }
  string s = toString(n) + "|" + to_string(k) + "|" + toString(flag);
  if(mp.find(s) != mp.end()) {
    return mp[s];
  }
  int res = 0;
  if(v[n - 1] >= 0) {
    if(flag == 0) {
      res = max(v[n - 1] + func(n - 1, k, 1), func(n - 1, k, 0));
    }
    else if(flag == 1) {
      res = v[n - 1] + func(n - 1, k, 1);
    }
  }
  else {
    if(flag == 0) {
      if(k > 0) {
        res = max(-v[n - 1] + func(n - 1, k - 1, 1), func(n - 1, k, 0));
      }
      else {
        res = func(n, k, 2);
      }
    }
    else if(flag == 1) {
      if(k > 0) {
        res = -v[n - 1] + func(n - 1, k - 1, 1);
      }
      else {
        res = func(n, k, 2);
      }
    }
  }
  return mp[s] = res;
}

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

  int cnt = 0;
  if(s[0] == '1') {
    cnt = 1;
  }
  else {
    cnt = -1;
  }
  // v.pb(0);
  for(int i = 1; i < n; i ++) {
    if(s[i] == '1') {
      if(cnt < 0) {
        v.pb(cnt);
        cnt = 1;
      }
      else {
        cnt ++;
      }
    }
    else {
      if(cnt > 0) {
        v.pb(cnt);
        cnt = -1;
      }
      else {
        cnt --;
      }
    }
  }
  v.pb(cnt);
  n = v.size();
  int i = 0, j = 0;
  int ans = 0;
  int sum = 0;
  while(j < n) {
    sum += abs(v[j]);
    if(v[j] < 0) {
      k --;
    }
    if(k < 0) {
      if(v[i] < 0) {
        sum -= abs(v[i]);
        i ++;
      }
      else {
        sum -= abs(v[i]);
        sum -= abs(v[i + 1]);
        i = i + 2;
      }
      k ++;
    }
    j ++;
    ans = max(ans, sum);
  }
  cout << ans, nl;
  return 0;
}

Measured memory_bytes: 1020