#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  long long n, p;
  cin >> n >> p;
  for (int i = 1; i <= 1000; i++) {
    long long cand = n - i * p;
    if (cand < 0) {
      cout << -1 << endl;
      return 0;
    }
    int nbits = __builtin_popcountll(cand);
    if (nbits == i) {
      cout << i << endl;
      return 0;
    } else if (nbits < i and cand >= i) {
      cout << i << endl;
      return 0;
    }
  }
}
