#include <bits/stdc++.h>
using namespace std;
long long mx, cnt, m, k, a[1001], f[101][101][2], now, la;
long long get(long long x) {
  long long i, j;
  cnt = 0;
  while (x) {
    cnt++;
    a[cnt] = x % 2;
    x /= 2;
  }
  now = 0;
  memset(f, 0, sizeof(f));
  f[0][0][0] = 1;
  for (i = 1; i <= cnt; i++)
    for (j = 0; j <= i; j++) {
      f[i][j][0] += f[i - 1][j][0] + f[i - 1][j][1];
      if (j) f[i][j][1] += f[i - 1][j - 1][0] + f[i - 1][j - 1][1];
    }
  for (i = 1; i < cnt; i++) {
    now += f[i][k][1];
  }
  la = k - 1;
  for (i = cnt - 1; i; i--) {
    if (la < 0) break;
    if (a[i]) {
      now += f[i][la][0], la--;
    }
  }
  return now;
}
long long check(long long mid) {
  long long i, h1 = get(mid + 1), h2 = get(mid * 2ll + 1);
  return h2 - h1;
}
int main() {
  long long l, r, mid;
  scanf("%lld%lld", &m, &k);
  l = 1;
  r = 1e18;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid) <= m) {
      mx = max(mx, mid);
      l = mid + 1;
    } else
      r = mid - 1;
  }
  printf("%lld", mx);
}
