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