#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
  int n, k;
  scanf("%d", &n), scanf("%d", &k);
  for (long long p = 1;; p++) {
    if ((1ll << (p - 1)) + k > 0 and (1ll << (p - 1)) + k > n) break;
    long long at = n - k * p;
    if (__builtin_popcountll(at) <= p and p <= at) return !printf("%lld\n", p);
  }
  printf("%d\n", -1);
  exit(0);
}
