#include <bits/stdc++.h>
using namespace std;
long long f(long long n) {
  long long res = 0;
  while (n > 0) {
    res += n % 2;
    n /= 2;
  }
  return res;
}
signed main() {
  long long n, p, ans = 1e9;
  cin >> n >> p;
  for (long long i = 0; i < 200000; i++) {
    if (n <= 0) break;
    if (f(n) <= i && n >= i) {
      ans = min(ans, i);
    }
    n -= p;
  }
  if (ans != 1e9)
    cout << ans;
  else
    cout << -1;
}
