#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long int n, p;
  cin >> n >> p;
  for (int i = 1;; i++) {
    n -= p;
    if (n <= 0) break;
    long long int x = __builtin_popcount(n);
    if (x <= i && i <= n) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << "-1" << '\n';
  return 0;
}
