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