#include <bits/stdc++.h>
using namespace std;
int n, p;
int calmin(int t) {
  int res = 0;
  while (t) {
    if (t % 2) {
      res++;
    }
    t /= 2;
  }
  return res;
}
int main(void) {
  cin >> n >> p;
  bool ok = false;
  for (int i = 1; i < 32; ++i) {
    int cur = n - i * p;
    if (cur < 0) {
      break;
    }
    if (calmin(cur) <= i && cur >= i) {
      ok = true;
      cout << i << endl;
      break;
    }
  }
  if (!ok) {
    cout << "-1" << endl;
  }
}
