#include <bits/stdc++.h>
using namespace std;
int n, p;
int main() {
  scanf("%d %d", &n, &p);
  for (int i = 1; i <= 100000; i++) {
    int nn = n - p * i;
    if (nn < i) continue;
    int nu = __builtin_popcount(nn);
    if (nu <= i) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
