#include <bits/stdc++.h>
using namespace std;
int a[1100];
bool mark[1100];
int num[1100];
int main() {
  int n, r;
  while (cin >> n >> r) {
    memset(a, 0, sizeof(a));
    memset(mark, 0, sizeof(mark));
    memset(num, 0, sizeof(num));
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      if (a[i]) {
        ans++;
        for (int j = i - r + 1; j <= i + r - 1; ++j) {
          if (j <= 0 || j > n) continue;
          num[j]++;
        }
      }
    }
    int flag = 1;
    for (int i = 1; i <= n; ++i) {
      if (num[i] == 0) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      for (int i = 1; i <= n; ++i) {
        if (a[i]) {
          int tt = 1;
          for (int j = i - r + 1; j <= i + r - 1; ++j) {
            if (j <= 0 || j > n) continue;
            if (num[j] < 2) {
              tt = 0;
            }
          }
          if (tt) {
            for (int j = i - r + 1; j <= i + r - 1; ++j) {
              if (j <= 0 || j > n) continue;
              num[j]--;
            }
            ans--;
          }
        }
      }
    }
    if (flag)
      cout << ans << endl;
    else
      cout << "-1" << endl;
  }
  return 0;
}
