#include <bits/stdc++.h>
using namespace std;
long long n, P;
bool ck(int c) {
  long long m = n - c * P;
  if (m < 0) return false;
  int cnt = 0;
  for (int i = 60; i >= 0; i--) cnt += (((m) >> (i)) & 1);
  return c <= m && c >= cnt;
}
void Solve() {
  for (int i = 1; i <= 40; i++)
    if (ck(i)) {
      printf("%d\n", i);
      return;
    }
  puts("-1");
}
int main() {
  cin >> n >> P;
  Solve();
  return 0;
}
