#include <bits/stdc++.h>
using namespace std;
void solve();
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
istream &operator>>(istream &in, vector<T> &ans) {
  for (auto &d : ans) in >> d;
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &ans) {
  for (auto &d : ans) out << d << " ";
  return out;
}
int main() { solve(); }
void solve() {
  long long n, p;
  cin >> n >> p;
  for (long long i = 1; i < 10000; ++i) {
    long long c = n - i * p;
    if (c < i) continue;
    if (c <= 0) break;
    int cnt = 0;
    while (c) {
      cnt += c % 2;
      c /= 2;
    }
    if (i >= cnt) {
      cout << i;
      return;
    }
  }
  cout << -1;
}
