#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, r;
  cin >> n >> r;
  long long int a[n];
  std::vector<long long int> b, c;
  for (long int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      long long int l = 0, k = n - 1;
      b.push_back(max(l, i - r + 1));
      c.push_back(min(k, i + r - 1));
    }
  }
  if (b.size() == 0) {
    cout << "-1";
    exit(0);
  }
  long long int x = b[0], y = c[0];
  for (long int i = 1; i < b.size(); i++) {
    if (b[i] > y + 1) {
      x = -1;
      y = -1;
      break;
    }
    x = min(x, b[i]);
    y = max(y, c[i]);
  }
  if (x != 0 || y != n - 1) {
    cout << "-1";
    exit(0);
  }
  for (long int i = 0; i < b.size(); i++) {
    long long int x1 = INT_MAX;
    long long int y1 = -3;
    for (long int j = 0; j < b.size(); j++) {
      if (i != j && b[j] >= 0 && c[j] >= 0) {
        if (b[j] > y1 + 1 && y1 >= 0) break;
        x1 = min(x1, b[j]);
        y1 = max(y1, c[j]);
      }
    }
    if ((x1 == 0) && (y1 == n - 1)) {
      b[i] = -7;
      c[i] = -7;
    }
  }
  long long int co = 0;
  for (long int i = 0; i < b.size(); i++) {
    if ((b[i] > -1) && (c[i] > -1)) {
      co++;
    }
  }
  cout << co;
  return 0;
}
