#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, p;
  cin >> n >> p;
  for (long long i = 1; i < 33; i++) {
    long long j = n - i * p;
    long long bits = 0, mbits = 0;
    if (j > 0)
      for (long long k = 0; k < 33; k++)
        if (((1ll << k) & j) != 0) {
          bits++;
          mbits += (1ll << k);
        }
    if (bits <= i && mbits >= i) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
