#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  int p, ans = -1;
  cin >> n >> p >> ans;
  for (int k = 1; k <= 31; k++) {
    if (n - k * p < 0) {
      continue;
    }
    if (__builtin_popcount(n - k * p) <= k && k <= n - k * p) {
      ans = k;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}
