#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
void solve() {
  long long n, p;
  cin >> n >> p;
  long long ans = inf;
  for (long long cnt = 1; cnt < 1e5; ++cnt) {
    if (n - cnt * p <= 0) continue;
    long long cur = n - cnt * p;
    long long t = cur;
    long long CNTbit = 0;
    while (cur != 0) {
      CNTbit += cur % 2;
      cur /= 2;
    }
    if (CNTbit <= cnt && cnt <= t) ans = min(ans, cnt);
  }
  if (ans == inf)
    cout << -1;
  else
    cout << ans;
}
int32_t main() {
  long long q = 1;
  while (q--) solve();
}
