#include <bits/stdc++.h>
using namespace std;
long long c[200][200];
long long k, m;
void comb(void) {
  int t = 100, i, j;
  c[0][0] = 1;
  for (i = 1; i <= t; i++) {
    c[i][0] = 1;
    for (j = 1; j < i; j++)
      if (j == 1)
        c[i][j] = i;
      else
        c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    c[i][j] = 1;
  }
}
long long calc(long long x) {
  long long t = 64, cnt = 0, tmp = x, mx = 0;
  long long i, j, temp, ans;
  for (i = 1; i <= t; i++) {
    if (tmp & 1) cnt++;
    if (tmp & 1) mx = i;
    tmp >>= 1;
  }
  temp = 0;
  if (cnt == k)
    ans = 1;
  else
    ans = 0;
  for (i = mx; i >= 1; i--) {
    tmp = x;
    for (j = 1; j < i; j++) tmp >>= 1;
    if (!(tmp & 1)) continue;
    if (k - temp <= 0) continue;
    ans += c[i - 1][k - temp];
    temp++;
  }
  return ans;
}
long long search(void) {
  long long top = 1e18, bot = 1, mid, tmp;
  while (bot <= top) {
    mid = (bot + top) / 2;
    tmp = calc(2 * mid) - calc(mid);
    if (tmp == m) break;
    if (tmp > m)
      top = mid - 1;
    else
      bot = mid + 1;
  }
  return mid;
}
int main(void) {
  comb();
  while (scanf("%I64d%I64d", &m, &k) != EOF) {
    printf("%I64d\n", search());
  }
  return 0;
}
