#include <bits/stdc++.h>
using namespace std;
class CPBinary {
 public:
  int numBits(int x) {
    if (x == 0) {
      return 0;
    }
    int counter = 0;
    for (int i = 0; i < 32; i++) {
      bool a = x & (1 << i);
      if (a == 1) {
        counter++;
      }
    }
    return counter;
  }
  void solve(std::istream& in, std::ostream& out) {
    long long n, p;
    in >> n >> p;
    int x = numBits(10);
    for (int i = 0; i < 32; i++) {
      long long x = n - i * p;
      if (x < i) {
        continue;
      }
      int a = numBits(x);
      if (a <= i) {
        out << i << endl;
        return;
      }
    }
    out << -1 << endl;
  }
};
int main() {
  CPBinary solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
