#include <bits/stdc++.h>
using namespace std;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) is >> x;
  return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];
  }
  return os;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, p;
  cin >> n >> p;
  for (int ans = 1; ans <= 64; ++ans) {
    long long x = n - p * (long long)ans;
    if (x >= ans && __builtin_popcountll(x) <= ans) {
      cout << ans << '\n';
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
