#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const long double PI = (long double)(3.1415926535897932384626433832795);
inline void yes() { cout << "Yes\n"; }
inline void no() { cout << "No\n"; }
inline void notposs() { cout << -1 << endl; }
bool solve(int cpy, int j) {
  multiset<int> s;
  int i = 0;
  while (cpy) {
    if (cpy % 2) {
      s.insert((1 << i));
    }
    ++i;
    cpy /= 2;
  }
  if (s.size() > j) {
    return false;
  }
  int k = j - s.size();
  while (k) {
    auto it = s.end();
    --it;
    if (*it == 1) {
      return false;
    }
    --k;
    s.erase(it);
    int val = *it;
    s.insert(val / 2);
    s.insert(val / 2);
  }
  return true;
}
void solve() {
  int n, p;
  cin >> n >> p;
  for (long long i = 0; i < 32; ++i) {
    if (n - i * p <= 0) return notposs();
    int aff = n - i * p;
    if (__builtin_popcount(aff) > i) {
      continue;
    }
    if (solve(aff, i)) {
      cout << i << endl;
      return;
    }
  }
  return notposs();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  for (long long i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
