#include <bits/stdc++.h>
int main() {
  long long n, p;
  std::cin >> n >> p;
  for (int i = 1; i <= 1000000000; ++i) {
    int x = n - i * p;
    if (x <= 0) break;
    if (i > x) continue;
    int tmp = 0;
    for (int j = 0; j < 33; ++j)
      if (x & (1LL << j)) ++tmp;
    if ((tmp <= i) && (tmp > 0)) {
      std::cout << i;
      return 0;
    }
  }
  std::cout << -1;
}
