#include <bits/stdc++.h>
using namespace std;
long long comb[105][105];
bool bits[64];
long long m, k;
long long cal(long long n) {
  long long res = 0;
  int cnt = 0;
  for (int i = 0; i < 64; i++) {
    bits[i] = n % 2;
    n /= 2;
  }
  for (int i = 63; i >= 0; i--) {
    if (bits[i] == 1) {
      int rem = k - cnt;
      if (rem >= 0) {
        res += comb[i][rem];
      }
      cnt++;
    }
  }
  return res;
}
int main() {
  comb[0][0] = 1;
  for (int i = 1; i <= 100; i++) {
    comb[i][0] = comb[i][i] = 1;
    for (int j = 1; j < i; j++) {
      comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]);
    }
  }
  scanf("%lld%lld", &m, &k);
  long long lo = 1, hi = 1e18, ans = 1;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    long long res = cal(mid * 2) - cal(mid);
    if (res <= m) {
      if (res == m) ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  printf("%lld\n", ans);
}
