#include <bits/stdc++.h>
using namespace std;
void print(vector<long long> v) {
  long long n = v.size();
  for (long long i = 0; i < n; i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b != 0) {
    if (b & 1) {
      res *= a;
    }
    a = (a * a);
    b = (b / 2);
  }
  return res;
}
bool y_n(long long n, long long k) {
  long long sum = k;
  vector<long long> v(k, 1);
  for (long long i = k - 1; i >= 0; i--) {
    while (sum + v[i] <= n) {
      sum += v[i];
      v[i] *= 2;
    }
  }
  return (sum == n);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, p;
  cin >> n >> p;
  for (long long i = 0; i <= 32; i++) {
    long long x = n - (p * i);
    if (y_n(x, i)) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
