#include <bits/stdc++.h>
using namespace std;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, p;
int main() {
  cin >> n >> p;
  for (int k = 1; k <= 1000; k++) {
    long long x = n - 1ll * k * p;
    if (x < 0) continue;
    if (__builtin_popcountll(x) <= k && x >= k) return cout << k, 0;
  }
  cout << -1;
  return 0;
}
