#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
const long long INF = 1000000000ll;
const long long LLINF = 1000000000000000000ll;
const long long MOD = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  long long n, p;
  cin >> n >> p;
  for (int l = (int)1; l <= (int)(100); l++) {
    long long a = n - l * p;
    if (a < 0) {
      continue;
    }
    long long cnt1 = 0, c = 0;
    for (int i = 0; i < (int)(32); i++) {
      if (a & (1ll << i)) {
        cnt1++;
        c += (1ll << i);
      }
    }
    if (l <= c && l >= cnt1) {
      cout << l << "\n";
      exit(0);
    }
  }
  cout << -1 << "\n";
  return 0;
}
