#include <bits/stdc++.h>
const long long base = 1000 * 1000 * 1000;
const double pi = 3.1415926535897932384626433832795;
int32_t step2(int32_t a) {
  if (a == 0) return 0;
  int32_t ans = 0;
  if (a % 2 == 1) {
    a -= 1;
    ans++;
    if (a == 0) return 1;
  }
  int32_t k = 1;
  while (a >= int32_t(pow(2, k))) k++;
  for (int32_t i = k; i >= 0; i--) {
    int32_t now = int32_t(pow(2, i));
    if (now <= a) {
      ans++;
      a -= now;
      i++;
    } else {
      continue;
    }
  }
  if (a == 0) return ans;
  return 0;
}
int32_t main() {
  using std::cin;
  using std::cout;
  using std::max;
  using std::min;
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int32_t n, p;
  cin >> n >> p;
  if (p + 1 > n) {
    cout << -1;
    return 0;
  }
  for (int32_t y = 1; n - y * p > 0 && y <= 100000; y++) {
    if (step2(n - y * p) <= y && n - y * p >= y) {
      cout << y;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
