#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
template <typename T>
istream& operator>>(istream& in, vector<T>& v) {
  for (int i = 0; i < v.size(); i++) {
    in >> v[i];
  }
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    out << v[i] << ' ';
  }
  return out;
}
int cnt(long long a) {
  int ans = 0;
  vector<int> b;
  while (a) {
    b.push_back(a % 2);
    a /= 2;
  }
  reverse(b.begin(), b.end());
  for (auto i : b) {
    ans *= 2;
    ans += i;
  }
  return ans;
}
int cnt2(long long a) {
  int res = 0;
  while (a) {
    res += a % 2;
    a /= 2;
  }
  return res;
}
void solve() {
  long long n, p;
  cin >> n >> p;
  for (int i = 1; i < 1e5 + 1; i++) {
    n -= p;
    if (n < 1) {
      cout << -1 << endl;
      return;
    }
    if (cnt(n) >= i && cnt2(n) <= i) {
      cout << i << endl;
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
