#include <bits/stdc++.h>
using namespace std;
const int dim = 1005;
pair<int, int> indexi[dim];
int n, a[dim], r, smen[dim], sume[dim], cntheat;
int main() {
  int i, cnt = 0, ok, j;
  cin >> n >> r;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      cntheat++;
      smen[max(1, i - r + 1)]++;
      smen[min(n, i + r - 1) + 1]--;
      indexi[i].first = max(1, i - r + 1);
      indexi[i].second = min(i + r - 1, n);
    }
  }
  for (i = 1; i <= n; i++) {
    smen[i] += smen[i - 1];
    sume[i] = smen[i] + sume[i - 1];
    if (smen[i] == 0) {
      cout << "-1";
      return 0;
    }
  }
  for (i = 1; i <= n; i++) {
    if (a[i] == 1) {
      ok = 0;
      for (j = indexi[i].first; j <= indexi[i].second && ok == 0; j++) {
        if (smen[j] == 1) {
          ok = 1;
        }
      }
      if (ok == 0) {
        for (j = indexi[i].first; j <= indexi[i].second; j++) {
          smen[j]--;
        }
        cnt++;
      }
    }
  }
  cout << cntheat - cnt;
  return 0;
}
