#include <bits/stdc++.h>
using namespace std;
int n, r;
int ar[10003] = {0};
int posi[10003] = {0};
int main() {
  cin >> n >> r;
  int ans = 0;
  int index = 0;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    if (ar[i] == 1) {
      ar[i] = 0;
      posi[index++] = i;
    }
  }
  for (int i = 0; i < index; i++) {
    for (int j = posi[i] - r + 1; j <= posi[i] + r - 1; j++) {
      ar[j] += 1;
    }
    ans++;
  }
  for (int i = 0; i < n; i++) {
    if (ar[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < index; i++) {
    bool judge = true;
    for (int j = max(posi[i] - r + 1, 0); j <= min(posi[i] + r - 1, n - 1);
         j++) {
      if (ar[j] == 1) {
        judge = false;
        break;
      } else if (ar[j] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (judge) {
      for (int j = max(posi[i] - r + 1, 0); j <= min(posi[i] + r - 1, n - 1);
           j++) {
        ar[j] -= 1;
      }
      ans--;
    } else {
      ar[posi[i]] = 1000;
    }
  }
  if (ans) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
