#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, k = 0;
  cin >> n >> p;
  while (n - p * k >= 0) {
    k++;
    if (__builtin_popcount(n - p * k) <= k) {
      break;
    }
  }
  if ((n - p * k) >= k)
    cout << k << endl;
  else
    cout << -1 << endl;
  return 0;
}
