#include <bits/stdc++.h>
using namespace std;
long long prime(long long n) {
  if (n <= 1) return 0;
  if (n <= 3) return 1;
  if (n % 2 == 0 || n % 3 == 0) return 0;
  for (long long i = 5; i * i <= n; i = i + 6) {
    if (n % i == 0 || n % (i + 2) == 0) return 0;
  }
  return 1;
}
void perfect() {
  long long n, p, i, j, ans = INT_MAX, k, a;
  cin >> n >> p;
  for (k = 1; n - p * k >= k; k++) {
    a = n - p * k;
    j = __builtin_popcount(a);
    if (j <= k) {
      cout << k << '\n';
      return;
    }
  }
  cout << "-1";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    perfect();
  }
  return 0;
}
