#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p;
  cin >> n >> p;
  int ans = -1;
  for (int i = 1; i < 40; i++) {
    long long m = n - p * i;
    if (m <= 0) break;
    int cnt = 0;
    long long m1 = m;
    while (m > 0) {
      cnt += m % 2;
      m /= 2;
    }
    if (i >= cnt && i <= m1) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
