#include <bits/stdc++.h>
using namespace std;
long long n, r, a[100004], c[100004], ans;
void ReadInPut() { cin >> n >> r; }
void Solve() {
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      ans++;
      for (int j = max((long long)1, i - r + 1); j <= min(n, i + r - 1); j++)
        c[j]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (c[i] == 0) {
      cout << -1 << '\n';
      return;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      int che = 0;
      for (int j = max((long long)1, i - r + 1); j <= min(n, i + r - 1); j++) {
        if (c[j] == 1) {
          che = 1;
          break;
        }
      }
      if (che == 0) {
        for (int j = max((long long)1, i - r + 1); j <= min(n, i + r - 1); j++)
          c[j]--;
        ans--;
      }
    }
  }
  cout << ans;
}
int main() {
  ReadInPut();
  Solve();
  long long qwer, qwe = 1234, wer = 213;
  qwer = qwe + wer;
  qwer = qwe * wer;
  qwer = qwe - wer;
  qwer = qwe / wer;
}
