#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
const int INF = 1000000007;
const long long INF2 = 1000000000000000007;
const long long MOD = 1e6;
const long long MOD1 = 1864463441;
const int SIZE = 150010;
long long n, p;
vector<pair<int, int> > vec;
int C_musor(long long x) {
  int cnt = 0;
  long long m = (1LL << 35);
  while (x) {
    if (x >= m) {
      x -= m;
      cnt++;
    }
    m /= 2;
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> p;
  for (int i = 1; i < 50; ++i) {
    long long C_pomoika = n - p * i;
    if (C_pomoika < i) continue;
    long long C_govno = C_musor(C_pomoika);
    if (C_govno <= i) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
