#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p;
  cin >> n >> p;
  for (long long i = 1; i < 1000; ++i) {
    long long final_target = n - i * p;
    if (final_target < i) {
      cout << -1 << endl;
      return 0;
    }
    int cnt = 0;
    while (final_target != 0) {
      cnt += final_target % 2;
      final_target /= 2;
    }
    if (cnt <= i) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
