#include <bits/stdc++.h>
using namespace std;
vector<long long> x;
long long bits(long long k) {
  long long c = 0;
  while (k != 0) {
    k = (k & (k - 1));
    c++;
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b;
  cin >> a >> b;
  long long i = 0;
  for (long long i = 1; i <= 31; i++) {
    a -= b;
    long long num = bits(a);
    if (num <= i) {
      long long j = i - num;
      long long counter = 0, bits = 0;
      bool pos = false;
      for (long long k = 31; k >= 0; k--) {
        if (j <= counter) {
          pos = true;
          break;
        } else {
          j -= counter;
        }
        counter *= 2;
        if ((1 << k) & (a)) {
          counter++;
        }
      }
      if (pos) {
        cout << i << "\n";
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
