#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p;
  cin >> n >> p;
  long long ans;
  if (n < (p + 1)) {
    cout << "-1";
    return 0;
  }
  for (long long i = 1; i <= 31; i++) {
    long long val = n - i * p;
    if (val < 0) {
      cout << "-1";
      return 0;
    }
    if (__builtin_popcount(val) <= i && val >= i) {
      cout << i;
      return 0;
    }
  }
}
