#include <bits/stdc++.h>
using namespace std;
long long countSetBits(long long n) {
  long long count = 0;
  while (n) {
    n &= (n - 1);
    count++;
  }
  return count;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, p;
  cin >> n >> p;
  long long ans = INT_MAX;
  for (int i = 1; i <= 5000; i++) {
    if (countSetBits(n - i * p) <= i && (n - i * p) >= i) {
      ans = min(ans, (long long)i);
    }
  }
  if (ans != INT_MAX) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
