#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, maxn = 100001;
long long C[66][66];
void init(int n = 62) {
  C[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  }
}
int main() {
  init();
  long long m;
  int k;
  while (~scanf("%I64d%d", &m, &k)) {
    if (k == 1 || m == 0) {
      printf("1\n");
      continue;
    }
    int n = k;
    while (1) {
      if (C[n - 2][k - 2] >= m) break;
      m -= C[n - 2][k - 2];
      n++;
    }
    long long ans = (1ll << (n - 1)) + 1;
    k -= 2;
    for (int i = n - 2; i && k; i--) {
      if (m > C[i - 1][k]) m -= C[i - 1][k], k--, ans += (1ll << i);
    }
    printf("%I64d\n", (ans + 1) >> 1);
  }
  return 0;
}
