#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int MAXM = 1000005;
const int MOD = 1000000007;
const int MAMOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
long long n, p;
int gao(long long x) {
  int cnt = 0;
  while (x) {
    x ^= x & -x;
    cnt++;
  }
  return cnt;
}
int main() {
  scanf("%lld%lld", &n, &p);
  for (long long i = 1; i <= MAXM; i++)
    if (n - p * i >= i && gao(n - p * i) <= i) {
      printf("%lld\n", i);
      return 0;
    }
  printf("-1\n");
  return 0;
}
