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