#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void solve() {
  long long n, p;
  cin >> n >> p;
  for (long long i = 1; i < 32; i++) {
    long long x = n - i * p;
    long long cnt = 0, cnt2 = 0;
    if (x < 0) break;
    for (long long j = 0; j < 32; j++) {
      if (x & (1 << j)) {
        cnt2 += 1 << j;
        cnt += 1;
      }
    }
    if (cnt <= i && cnt2 >= i) {
      cout << i << '\n';
      return;
    }
  }
  cout << -1 << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
