#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, p, cnt = 0;
  cin >> n >> p;
  if (n - p == 1) {
    cout << 1;
    return 0;
  }
  while (n - p * cnt > 0) {
    long long int x = 0, y = 1;
    for (long long int i = 0; i < 35; i++) {
      if ((n - p * cnt) & y) {
        x += i;
      }
      y *= 2;
    }
    if (n - p * cnt > 0 && __builtin_popcount(n - p * cnt) <= cnt &&
        __builtin_popcount(n - p * cnt) + x >= cnt &&
        (!(n - p * cnt == 1 && cnt > 0))) {
      cout << cnt;
      return 0;
    }
    cnt += 1;
    if (cnt >= 1e7) {
      cout << -1;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
