#include <bits/stdc++.h>
using namespace std;
int N, p;
int bits(int N) {
  int ret = 0;
  while (N) {
    ret += N % 2;
    N /= 2;
  }
  return ret;
}
int main() {
  cin >> N >> p;
  for (int k = 0; k <= 30; ++k) {
    int val = N - k * p;
    if (val >= k && bits(val) <= k) {
      cout << k << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}
