#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long MAX = 510000;
const long long INF = 1LL << 60;
const long long MOD = 1000000007LL;
using namespace std;
long long bit_count(long long n) {
  long long res = 0;
  while (n > 0) {
    if (n & 1) res++;
    n /= 2;
  }
  return res;
}
int main() {
  long long n, p;
  scanf("%lld %lld", &n, &p);
  for (long long i = 1; i <= 60; i++) {
    long long t = n - i * p;
    if (t < 0) break;
    if (bit_count(t) <= i && i <= t) {
      printf("%lld\n", i);
      return 0;
    }
  }
  puts("-1");
  return 0;
}
