#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, p;
  cin >> n >> p;
  for (long long k = 1; k <= 1e6; k++) {
    long long alu = n - k * p;
    if (alu < 0) break;
    long long bits = __builtin_popcountll(alu);
    if (k >= bits and k <= alu) {
      cout << k;
      return 0;
    }
  }
  cout << "-1";
}
