#include <bits/stdc++.h>
using namespace std;
bool check(long long int n, long long int k) {
  long long int sum = k;
  long long int A[k];
  fill(A, A + k, 1);
  for (long long int i = k - 1; i >= 0; --i) {
    while (sum + A[i] <= n) {
      sum += A[i];
      A[i] *= 2;
    }
  }
  if (sum != n) {
    return 0;
  }
  return 1;
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(NULL);
  long long int a, b;
  cin >> a >> b;
  for (long long int i = 0; i < 33; i++) {
    long long int x = a - i * (b);
    if (check(x, i)) return cout << i << '\n', 0;
  }
  cout << -1 << '\n';
  return 0;
}
