#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  long long int n, p;
  cin >> n >> p;
  for (long long int k = 1; k <= 40; ++k) {
    long long int x = n - k * p;
    int b = __builtin_popcount(x);
    if (x >= k && b <= k) {
      cout << k << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
