#include <bits/stdc++.h>
using namespace std;
const int mxN = 200001;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, p;
  cin >> n >> p;
  int ans = -1;
  for (int l = 1; l <= 34; ++l) {
    int x = __builtin_popcount(n - l * p);
    if (x <= l && l <= (n - l * p)) {
      ans = l;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
