#include <bits/stdc++.h>
using namespace std;
int gcd(int A, int B) {
  if (!B) return A;
  return gcd(B, A % B);
}
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = 1; i < 100000; i++) {
    int num = n - p * i;
    if (num >= i) {
      if (__builtin_popcount(num) <= i) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
}
