#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  cin >> n >> p;
  if (p >= n) return puts("-1"), 0;
  for (int k = 1;; k++) {
    long long m = n - (long long)k * p;
    if (m < 0 && p > 0) break;
    if (m >= k && __builtin_popcountll(m) <= k) {
      printf("%d\n", k);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
