#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
  uniform_int_distribution<long long> uid(l, r);
  return uid(rng);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, p;
  cin >> n >> p;
  long long val = 1;
  long long ans = 1e9;
  for (long long k = 1; k <= 1000; k++) {
    long long val = n - k * p;
    if (val < 0) break;
    long long req = __builtin_popcountll(n - k * p);
    if (req <= k && k * (p + 1) <= n) ans = min(ans, max(k, req));
  }
  if (ans == 1e9) ans = -1;
  cout << ans;
  return 0;
}
