#include <bits/stdc++.h>
using namespace std;
const long long oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, p;
  cin >> n >> p;
  for (long long k = (1); k < (40); k++) {
    long long x = n - k * p;
    if (x >= k && __builtin_popcountll(x) <= k) {
      cout << k << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
