#include <bits/stdc++.h>
using namespace std;
long long k = 0, n, t, i, j, m, d, x, s = 0;
string s1;
const long long N = 200010;
long long modPow(long long a, long long x, long long p) {
  long res = 1;
  while (x > 0) {
    if (x % 2 != 0) {
      res = (res * a) % p;
    }
    a = (a * a) % p;
    x /= 2;
  }
  return res;
}
long long modInverse(long long a, long long p) { return modPow(a, p - 2, p); }
signed main() {
  cin >> n >> m;
  long long c = 0, c1 = 0;
  for (i = 1; i <= 100000; i++) {
    n -= m;
    if (n <= 0) break;
    c = 0, c1 = 0;
    for (j = 34; j >= 0; j--) {
      if ((n >> j) & 1) {
        c1++;
        c += (long long)1 << j;
      }
    }
    if (i >= c1 and i <= c) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
