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