#include <bits/stdc++.h>
long long c[65][65];
long long choose(int n, int r) {
  if (n == r || r == 0) return c[n][r] = 1;
  if (r == 1) return c[n][r] = n;
  if (c[n][r]) return c[n][r];
  return c[n][r] = choose(n - 1, r) + choose(n - 1, r - 1);
}
int bitCount(long long n) {
  int count = 0;
  long long bit = 1;
  for (int i = 0; i < 64; i++) {
    if (bit & n) count++;
    bit = bit << 1;
  }
  return count;
}
long long count(long long n, int k) {
  int bC = bitCount(n), count = 0, r;
  long long bit = 1, c = 0;
  for (int i = 0; i < 64 && bC > count; i++) {
    if (bit & n) {
      count++;
      r = k - (bC - count);
      if (i >= r && r >= 0) c += choose(i, r);
    }
    bit = bit << 1;
  }
  if (bC == k) c++;
  return c;
}
int main() {
  long long max = 1e18, m;
  int k;
  std::cin >> m >> k;
  long long lo = 1, hi = max, mi, c;
  while (true) {
    mi = (lo + hi) / 2;
    c = count(mi * 2, k) - count(mi, k);
    if (c < m)
      lo = mi + 1;
    else if (c > m)
      hi = mi - 1;
    else {
      std::cout << mi;
      return 0;
    }
  }
}
