#include <bits/stdc++.h>
using namespace std;
class trio {
 public:
  int first, second, third;
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, p;
  cin >> n >> p;
  for (int i = 1; i < 41; ++i) {
    long long x = n - i * p;
    int mini = __builtin_popcount(x);
    if (x >= i && mini <= i) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1;
  return 0;
}
