#include <bits/stdc++.h>
using namespace std;
int sum[100005];
int main() {
  int n, k;
  cin >> n >> k;
  int s[100005];
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  int i = 0, j = 0;
  while (i < n) {
    int x = s[i], sum1 = 0;
    while (i < n) {
      if (s[i] == x) {
        sum1++;
        i++;
      } else {
        sum[j] = sum1;
        j++;
        break;
      }
    }
  }
  int ans = 0, add;
  if (s[0] == 0) {
    if (k * 2 <= j + 1) {
      add = 0;
      for (int l = 0; l < k * 2; l++) {
        add += sum[l];
      }
      ans = max(add, ans);
    }
  }
  if (s[n - 1] == 0) {
    if (k * 2 <= j + 1) {
      add = 0;
      for (int l = n - 1; l < k * 2; l--) {
        add += sum[l];
      }
      ans = max(add, ans);
    }
  }
  if (k * 2 + 1 <= j) {
    for (int l = (s[0] ? 0 : 1); l + k * 2 <= j - 1; l += 2) {
      add = 0;
      for (int m = 0; m < k * 2 + 1; m++) {
        add += s[l + m];
      }
      ans = max(ans, add);
    }
  } else
    ans = n;
  cout << ans << endl;
  return 0;
}
