#include <bits/stdc++.h>
using namespace std;
using INT = long long;
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = 0; i <= 1000; i++) {
    int t = n - i * p;
    if (t < i) continue;
    if (__builtin_popcount(t) <= i) {
      cout << i << endl;
      return 0;
    }
  }
  puts("-1");
  return 0;
}
