#include <bits/stdc++.h>
using namespace std;
int n, p;
long long cur;
int main() {
  cin >> n >> p;
  for (long long i = 1; i < 100000; i++) {
    cur = n - i * p;
    if (cur >= 0 && __builtin_popcountll(cur) <= i && i <= cur) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
