#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, a, k;
  cin >> n >> p;
  for (int i = 1; i <= 10000; i++) {
    a = n - i * p;
    k = __builtin_popcount(a);
    if (i >= k && a >= i) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
