#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, p;
  cin >> n >> p;
  int ans = -1;
  for (int i = 1;; i++) {
    int cur = n + p * (-i);
    if (cur < 0) {
      break;
    }
    int deg_cnt = 0;
    int bit_cnt = 0;
    for (int j = 0; j < 31; j++) {
      if ((cur >> j) & 1) {
        deg_cnt += j + 1;
        bit_cnt++;
      }
    }
    if (deg_cnt >= i && i >= bit_cnt) {
      ans = i;
      break;
    }
  }
  cout << ans;
  return 0;
}
