#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  bool flg = false;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') flg = true;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
  return flg ? -x : x;
}
int n, p;
void solve() {
  n = read(), p = read();
  int z = -1;
  for (int i(1), _i(60); i <= _i; i++) {
    if (p * i > n) continue;
    int t = n - p * i;
    if (__builtin_popcount(t) <= i && i <= t) {
      z = i;
      break;
    }
  }
  printf("%d\n", z);
}
int main() {
  for (int T = 1; T--;) solve();
  return 0;
}
