#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, r;
  cin >> n >> r;
  int a[n];
  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  r--;
  for (int i = 0; i < n; i++) {
    if ((a[i] != 2) || (a[i] != 3)) {
      int h1 = i + r;
      int h2 = i - r;
      if (h1 > n) {
        h1 = n - 1;
      }
      if (h2 < 0) {
        h2 = 0;
      }
      for (int p = h1; p >= h2; p--) {
        if ((a[p] == 1) || (a[p] == 3)) {
          res++;
          int h12 = p + r;
          int h21 = p - r;
          if (h12 > n) {
            h12 = n - 1;
          }
          if (h21 < 0) {
            h21 = 0;
          }
          for (int g = h12; g >= h21; g--) {
            if (a[g] == 1) {
              a[g] = 3;
            }
            if (a[g] == 0) {
              a[g] = 2;
            }
          }
          i = h12;
          break;
        }
      }
      if ((a[i] == 0) || (a[i] == 1)) {
        res = -1;
        break;
      }
    }
  }
  cout << res;
  return 0;
}
