#include <bits/stdc++.h>
using namespace std;
long long n, p;
void input() { cin >> n >> p; }
void solve() {
  long long r[31] = {0};
  r[0] = r[1] = 1;
  for (long long i = 2; i <= 30; i++) r[i] = 2 * r[i - 1];
  for (long long i = 1; i <= 1000000; i++) {
    long long t = n - p * i, x = (1ll) << 32, y = 0;
    if (p * i > n) break;
    for (long long k = 30; k >= 0; k--)
      if (t >= ((1ll) << k)) x |= (1ll) << k, t -= (1ll) << k;
    long long z = 0;
    for (long long k = 30; k >= 0; k--)
      if ((x & ((1ll) << k)) != 0) y++, z += r[k];
    if ((y == i) or (y <= i and z >= i and !t)) {
      cout << i;
      return;
    }
  }
  cout << -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  long long t;
  t = 1;
  while (t--) {
    input();
    solve();
  }
  cin.get();
  return 0;
}
