#include <bits/stdc++.h>
using namespace std;
int nbits(int n) {
  int count = 0;
  while (n > 0) {
    count++;
    n = n & (n - 1);
  }
  return count;
}
int main() {
  int n, p, k;
  int flag = 0;
  cin >> n >> p;
  for (int i = 1; i <= 31; i++) {
    if (n - p * i >= i) {
      int s = nbits(n - p * i);
      if (s <= i) {
        k = i;
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0) {
    cout << -1 << endl;
  } else {
    cout << k << endl;
  }
}
