#include <bits/stdc++.h>
using namespace std;
bool fun(int n, int count) {
  int temp = n;
  long long int sum = 0;
  for (int i = 31; i >= 0; i--) {
    int q = n / pow(2, i);
    sum += pow(2, i) * q;
    n -= q * pow(2, i);
    if (n <= 0) break;
  }
  if (sum >= count && __builtin_popcount(temp) <= count) return true;
  return false;
}
int main() {
  long long n, p;
  cin >> n >> p;
  long long count = 0;
  for (int i = 0; i < 32; i++) {
    n -= p;
    count++;
    if (fun(n, count)) {
      cout << count << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
