#include <bits/stdc++.h>
const int MAXN = 100100;
int CountBits(int n) {
  int ans = 0;
  while (n) {
    if (n & 1) ++ans;
    n >>= 1;
  }
  return ans;
}
int main() {
  int n, p, ans = 1, m;
  scanf("%d%d", &n, &p);
  while ((m = n - p * ans) > 0) {
    if (CountBits(m) <= ans && m >= ans) {
      printf("%d\n", ans);
      return 0;
    }
    ++ans;
  }
  puts("-1");
  return 0;
}
