#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, p;
  cin >> n >> p;
  long long cnt = 1;
  while (1) {
    long long y = n - cnt * p;
    if (y < 0) {
      break;
    }
    int no_bits = __builtin_popcount(y);
    if (cnt >= no_bits && y >= cnt) {
      cout << cnt;
      return 0;
    }
    cnt++;
  }
  cout << "-1";
  return 0;
}
