#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, inf = 1e9 + 7, mod = 1e9 + 7;
const long double eps = 1e-12;
const long long linf = (long long)1e18 + 7;
long long n, r, a[1020], u[1020], cnt = 0;
int main() {
  cin >> n >> r;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    u[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      cnt++;
      for (int j = max(1ll, i - r + 1); j <= min(n, i + r - 1); j++) {
        u[j]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (u[i] == 0) {
      cout << "-1";
      return 0;
    }
    if (a[i] == 1) {
      bool ok = true;
      for (int j = max(1ll, i - r + 1); j <= min(n, i + r - 1); j++) {
        if (u[j] < 2) {
          ok = false;
        }
      }
      if (!ok) {
        continue;
      }
      cnt--;
      for (int j = max(1ll, i - r + 1); j <= min(n, i + r - 1); j++) {
        u[j]--;
      }
    }
  }
  cout << cnt;
}
