#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  int n, p;
  cin >> n >> p;
  for (int i = 1; i < 100000; ++i) {
    int val = n - p * i;
    if (val <= 0) {
      cout << -1 << endl;
      return 0;
    }
    int bits = __builtin_popcount(val);
    int can = 0;
    int have[30] = {};
    for (int j = 0; j < 30; j++) {
      if (val & (1 << j)) {
        have[j] += 1;
      }
    }
    for (int j = 29; j > 0; j--) {
      while (have[j] && bits < i) {
        bits -= 1;
        bits += 2;
        have[j] -= 1;
        have[j - 1] += 2;
      }
    }
    if (bits == i) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
