#include <bits/stdc++.h>
using namespace std;
int read() {
  int a = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) {
    f = c == '-';
    c = getchar();
  }
  while (isdigit(c)) {
    a = a * 10 + c - 48;
    c = getchar();
  }
  return f ? -a : a;
}
int main() {
  long long N, p;
  cin >> N >> p;
  int cnt = 0;
  while (++cnt) {
    N -= p;
    if (N < cnt) {
      puts("-1");
      return 0;
    }
    if (__builtin_popcount(N) <= cnt && N >= cnt) {
      cout << cnt;
      return 0;
    }
  }
  return 0;
}
