#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = 1; i < 100; i++) {
    int m = n - i * p;
    if (m <= 0) {
      break;
    }
    if (m >= 0) {
      int pc = __builtin_popcount(m);
      if (pc <= i && i <= m) {
        cout << i;
        return 0;
      }
    }
  }
  cout << "-1\n";
  return 0;
}
