#include <bits/stdc++.h>
using namespace std;
void fio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fio();
  long long int n, p;
  cin >> n >> p;
  long long int ans = -1;
  for (int i = 1; i < 10000001; i++) {
    long long int temp = p * i;
    long long int u = n - temp;
    if (u <= 0) {
      ans = -1;
      break;
    }
    if (__builtin_popcountll(u) <= (long long int)(i) && i <= u) {
      ans = i;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
