#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
const int mod2 = 1e9 + 9;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main() {
  long long n, p;
  cin >> n >> p;
  for (long long i = 1; i <= 1000000; i++) {
    long long num = n - p * i;
    if (num >= i && __builtin_popcountll(num) <= i) return cout << i << "\n", 0;
  }
  cout << "-1\n";
  return 0;
}
