#include <bits/stdc++.h>
using namespace std;
void par(int a[], int n) {
  for (long long int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
}
void pv(vector<long long int> a) {
  for (long long int i = 0; i < a.size(); i++) {
    cout << a[i] << " ";
  }
}
long long int ceiling(long long int n, long long int m) {
  if (n % m == 0)
    return n / m;
  else
    return n / m + 1;
}
long long int fact(long long int n);
long long int nCr(long long int n, long long int r) {
  return fact(n) / (fact(r) * fact(n - r));
}
bool isprime(long long int n) {
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}
long long int fact(long long int n) {
  int res = 1;
  for (int i = 2; i <= n; i++) res = res * i;
  return res;
}
long long int bin_exp(long long int a, long long int n) {
  long long int res = 1;
  while (n) {
    if (n % 2) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    n /= 2;
  }
  return res;
}
bool seive(long long int n) {
  long long int prime[n + 1];
  memset(prime, 1, sizeof(prime));
  for (int i = 2; i * i <= n; i++) {
    if (prime[i] == 1) {
      for (int j = i * i; j <= n; j++) {
        prime[i] = 0;
      }
    }
  }
  return prime[n];
}
void re() {
  long long int n, k;
  cin >> n >> k;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long int> b(n);
  for (long long int i = 0; i < n; i++) {
    if (a[i] == 1) {
      long long int j = i;
      while (j < n && j < (i + k)) {
        b[j]++;
        j++;
      }
      j = (i - 1);
      while (j >= 0 && j > (i - k)) {
        b[j]++;
        j--;
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (b[i] == 0) {
      cout << -1 << endl;
      return;
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if (a[i] == 1) {
      long long int j = i;
      long long int f = 0;
      while (j < n && j < (i + k)) {
        if (b[j] == 0) {
          cout << -1 << endl;
          return;
        } else if (b[j] == 1) {
          f = 1;
        }
        j++;
      }
      j = (i - 1);
      while (j >= 0 && j > (i - k)) {
        if (b[j] == 0) {
          cout << -1 << endl;
          return;
        } else if (b[j] == 1) {
          f = 1;
        }
        j--;
      }
      if (f == 0) {
        j = i;
        while (j < n && j < (i + k)) {
          b[j]--;
          j++;
        }
        j = (i - 1);
        while (j >= 0 && j > (i - k)) {
          b[j]--;
          j--;
        }
      } else {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
  ;
  re();
}
