#include <bits/stdc++.h>
using namespace std;
int check(int ii, int x) {
  int minn = 0, maxn = 0;
  for (int i = 0; x; x >>= 1, i++) {
    if (x & 1) {
      minn++;
      maxn += (1 << i);
    }
  }
  if (ii >= minn && ii <= maxn)
    return 1;
  else
    return 0;
}
int main() {
  int n, p, ans = -1;
  cin >> n >> p;
  for (int i = 1; i <= 30; i++) {
    if (n - i * p <= 0) break;
    if (check(i, n - i * p)) {
      ans = i;
      break;
    }
  }
  cout << ans;
  return 0;
}
