#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long f[70][70][2];
long long c[70][70];
long long bit(long long i, long long j) { return (i >> j) & (1ll); }
long long dem(long long n) {
  long long i, kq = 0, d = 0;
  for (i = 63; i >= 0 && d <= k; --i) {
    if (bit(n, i)) {
      kq += c[k - d][i];
      d++;
    }
  }
  return kq;
}
int main() {
  scanf("%I64d%I64d", &n, &k);
  long long i, j;
  for (i = 0; i <= 63; ++i) c[0][i] = 1;
  for (i = 1; i <= 63; ++i) {
    for (j = 1; j <= 63; ++j) c[i][j] = c[i][j - 1] + c[i - 1][j - 1];
  }
  long long l = 1, r = 1000000000000000000ll, mid, tg;
  while (l <= r) {
    mid = (l + r) / 2;
    tg = dem(2 * mid) - dem(mid);
    if (tg == n) {
      printf("%I64d", mid);
      return 0;
    }
    if (tg > n)
      r = mid - 1;
    else
      l = mid + 1;
  }
}
