#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, p;
  cin >> n >> p;
  for (int k = 0; k < 31; ++k) {
    int m = n - k * p;
    if (m < 0) continue;
    int b = 0;
    for (int x = 0; x < 31; ++x)
      if (m & (1 << x)) ++b;
    if (b <= k && k <= m) {
      cout << k;
      return 0;
    }
  }
  cout << -1;
}
