#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  cin >> n >> p;
  for (int i = 1; i <= 31; i++) {
    int k = n - (i * p);
    if (k < 0 || k < i) {
      cout << -1;
      return 0;
    }
    int cnt = 0;
    while (k > 0) {
      cnt += (k & 1);
      k >>= 1;
    }
    if (cnt <= i && cnt != 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
