#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
const int N = 2e5 + 5, MOD = 1e9 + 7;
const long double EPS = 1e-9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, n, p;
  cin >> n >> p;
  long long mn = -1;
  for (i = 1; i <= 40; i++) {
    long long a = n - i * p;
    if (a < i) continue;
    if (__builtin_popcountll(a) <= i) {
      mn = i;
      break;
    }
  }
  cout << mn;
  return 0;
}
