#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long power(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = (ans * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, p;
  cin >> n >> p;
  for (long long i = 1; i <= 100000; i++) {
    long long val = n - i * p;
    if (val < i) continue;
    long long cnt = __builtin_popcount(val);
    if (cnt <= i) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
