#include <bits/stdc++.h>
using namespace std;
struct __timestamper {};
const long long INF = 1e18;
long long solve(long long n, long long p) {
  long long ans = INF;
  for (long long cnt = 0; cnt <= 2e6; cnt++) {
    long long m = n - p * cnt;
    if (m < 0) continue;
    long long cur = (long long)__builtin_popcountll(m);
    if (cur <= cnt && m >= cnt) {
      ans = min(ans, cnt);
    }
  }
  if (ans == INF) ans = -1;
  return ans;
}
int main() {
  long long n, p;
  while (cin >> n >> p) {
    cout << solve(n, p) << endl;
  }
  return 0;
}
