#include <bits/stdc++.h>
using namespace std;
long long n, p;
inline int read() {
  int num = 0;
  char g = getchar();
  while (g < 48 || 57 < g) g = getchar();
  while (47 < g && g < 58)
    num = (num << 1) + (num << 3) + g - 48, g = getchar();
  return num;
}
int main() {
  cin >> n >> p;
  long long s = 0;
  for (long long x = 0; x <= 100; x++) {
    long long t = n - x * p;
    if (t < x) continue;
    long long h = 0;
    for (int c = 40; c >= 0; c--) {
      if ((1ll << c) <= t) t -= (1ll << c), h++;
    }
    if (h <= x) {
      cout << x << endl;
      return 0;
    }
  }
  if (n != 0)
    puts("-1");
  else
    cout << s << endl;
  return 0;
}
