#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
char vow[] = {'a', 'e', 'i', 'o', 'u'};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
const int N = 1e6 + 30;
const long long int mod = 9982443530000;
int n, p, sm;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  cin >> n >> p;
  int l = 1, r = 31, ans = -1;
  for (int mid = 0; mid < 31; mid++) {
    sm = n - p * mid;
    if (sm < 0) break;
    int mkqan = 0;
    for (int i = 0; i < 31; i++) {
      if ((1 << i) & sm) mkqan++;
    }
    if (mkqan <= mid && mid <= sm) {
      cout << mid;
      return 0;
    }
  }
  cout << ans;
  return 0;
}
