#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long N = 100000;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, second> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename first, typename second>
ostream &operator<<(ostream &os, const map<first, second> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
multiset<long long> getPow(long long n) {
  multiset<long long> res;
  long long cnt = 0;
  while (n > 0) {
    if (n & 1) {
      res.insert(cnt);
    }
    cnt++;
    n /= 2;
  }
  return res;
}
bool pos(long long n, long long p, long long m) {
  n += (m * (-p));
  multiset<long long> temp = getPow(n);
  if (temp.size() > m or n <= 0) {
    return false;
  }
  while (temp.size() < m) {
    auto it = temp.end();
    it--;
    long long num = *it;
    if (num == 0) break;
    temp.erase(it);
    temp.insert(num - 1);
    temp.insert(num - 1);
  }
  return temp.size() == m;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long p;
  cin >> p;
  for (long long i = 0; i <= 1e5; i++) {
    if (pos(n, p, i)) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}
