#include <bits/stdc++.h>
using namespace std;
int count1(int x) {
  int ans = 0;
  while (x) {
    ans += x & 1;
    x >>= 1;
  }
  return ans;
}
int main() {
  int n, p;
  cin >> n >> p;
  for (int x = 0; x * (p + 1) <= n; x++)
    if (count1(n - x * p) <= x) {
      cout << x;
      return 0;
    }
  cout << -1;
}
