#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t = 1;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int ans = -1;
    for (long long int i = 1;; i++) {
      long long int p = n + ((-1) * (i)*k);
      if (p < i) break;
      long long int c = 0;
      while (p > 0) {
        if (p % 2 == 1) c++;
        p /= 2;
      }
      if (c <= i) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
}
