#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long nax = 2e5 + 69;
const long long inf = 9e18 + 69;
using pii = pair<long long, long long>;
void solve() {
  long long n, p;
  cin >> n >> p;
  long long ans = 0;
  if (p >= n) {
    cout << -1 << endl;
    return;
  }
  while (1) {
    long long curr = n - ans * p, cnt = __builtin_popcountll(curr);
    if (curr < 0) break;
    if (cnt <= ans && ans <= curr) {
      cout << ans << endl;
      return;
    }
    ans++;
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1, t1 = 1;
  while (t--) {
    solve();
  }
  return 0;
}
