#include <bits/stdc++.h>
using namespace std;
long long n, k, s;
int cnt, w;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n - i * k; i++) {
    s = n - i * k;
    cnt = 0;
    w = 0;
    while (s) {
      if (s & (1 << w)) s -= (1 << w), cnt++;
      w++;
    }
    if (cnt <= i) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
