#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2e9;
const long long INFLL = 1e18;
const int MAX_N = 1;
long long N, P;
int main() {
  cin >> N >> P;
  int ans = 0;
  while (N >= ans) {
    int cnt = 0;
    long long M = N;
    while (M > 0) {
      cnt += (M % 2);
      M /= 2;
    }
    if (cnt <= ans) {
      cout << ans;
      return 0;
    }
    N -= P;
    ans++;
  }
  printf("-1");
  return 0;
}
