#include <bits/stdc++.h>
using namespace std;
int c(long long a) {
  int ans = 0;
  while (a) {
    a &= a - 1;
    ans++;
  }
  return ans;
}
int main() {
  long long a, p, mn = -1;
  cin >> a >> p;
  if (a < 1 + p) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i < 40; i++) {
    if (c(a - p) <= i && a - p >= i) {
      cout << i;
      return 0;
    }
    a -= p;
  }
  cout << -1;
  return 0;
}
