#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000007, mod = inf, maxN = 75;
long long l, r, g, k, c[maxN][maxN];
void init() {
  c[0][0] = 1LL;
  for (int i = 1; i < maxN; i++) {
    c[i][0] = 1LL;
    for (int j = 1; j <= i; j++)
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
  }
}
long long f(long long a) {
  long long a1 = a, ret = 0, bit = 0, b = 0;
  while (a1 > 0) {
    if (a1 & 1) bit++;
    a1 >>= 1;
    b++;
  }
  if (bit == k) ret++;
  bit = 0;
  for (int i = b - 1; i >= 0; i--)
    if (1 & (a >> i)) {
      if (k >= bit) ret = (ret + c[i][k - bit]) % mod;
      bit++;
    }
  return ret;
}
int main() {
  scanf("%I64d %I64d", &g, &k);
  init();
  l = 0;
  r = inf;
  while (l < r - 1) {
    long long m = (l + r) >> 1;
    if (f(m << 1) - f(m) >= g)
      r = m;
    else
      l = m;
  }
  printf("%I64d\n", r);
  return 0;
}
