#include <bits/stdc++.h>
using namespace std;
int bts(long long k) {
  int ans = 0;
  for (long long mask = 1; mask <= k; mask <<= 1) {
    if (mask & k) {
      ++ans;
    }
  }
  return ans;
}
int main() {
  long long n, p;
  cin >> n >> p;
  long long t = 1;
  while (n - t * p > 0) {
    if (bts(n - t * p) <= t && n - t * p >= t) {
      cout << t;
      return 0;
    }
    ++t;
  }
  cout << -1;
  return 0;
}
