#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int N = 1e5 + 7;
const int MOD = 1e9 + 7;
inline long long int Max(const long long int &x, const long long int &y) {
  return x > y ? x : y;
}
inline long long int Min(const long long int &x, const long long int &y) {
  return x > y ? y : x;
}
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long int readl() {
  char ch = getchar();
  long long int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int solve(long long int x) {
  int cnt = 0;
  while (x) {
    if (x & 1) cnt++;
    x >>= 1;
  }
  return cnt;
}
int main() {
  long long int n, p;
  cin >> n >> p;
  for (int k = 0; k <= 60; k++) {
    long long int tmp = n - 1ll * k * p;
    if (tmp >= k) {
      if (solve(tmp) <= k) {
        cout << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
