#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 1000000007;
constexpr double EPS = 1e-8;
long long int N, M, K, H, W, L, R;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  for (int i = 1; i <= 60; i++) {
    M = N - K * i;
    int num = 0;
    if (M <= 0) continue;
    while (M) {
      num += M & 1;
      M >>= 1;
    }
    if (i >= num && i <= N - K * i) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
