#include <bits/stdc++.h>
using namespace std;
#pragma gcc target("sse4")
const long long MAXN = 1e5 + 9;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, p;
  cin >> n >> p;
  for (long long a = 1; a <= 50; a++) {
    long long x = n - a * p;
    if (x <= 0) continue;
    long long t = 0;
    for (long long e = 1; e <= x; e *= 2) {
      if (e & x) t++;
    }
    if (t <= a && a <= x) {
      cout << a;
      return 0;
    }
  }
  cout << -1;
}
