#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long llu;
const unsigned int LIM = 65;
llu ncr[LIM][LIM];
llu countsum(llu n, unsigned int k) {
  llu ans = 0, lg2n = 0, b;
  unsigned int idx;
  unsigned int binum[LIM];
  while (n > 0) {
    binum[lg2n++] = (n & 1);
    n >>= 1;
  }
  reverse(binum, binum + lg2n);
  lg2n--;
  idx = 0;
  b = lg2n;
  if (k > b + 1) return 0;
  while (k > 0) {
    if (binum[idx]) {
      if (k == 1) {
        ans += b + 1;
        break;
      }
      ans += ncr[b][k];
      k--;
    }
    idx++;
    if (b == 0) break;
    b--;
  }
  return ans;
}
void fill_ncr() {
  for (unsigned int i = 0; i < LIM; i++) memset(ncr[i], 0, sizeof(ncr[i]));
  ncr[1][1] = 1;
  for (unsigned int n = 0; n < LIM; n++) ncr[n][0] = 1;
  for (unsigned int n = 1; n < LIM; n++)
    for (unsigned int r = 1; r < LIM; r++)
      ncr[n][r] = ncr[n - 1][r - 1] + ncr[n - 1][r];
  return;
}
int main() {
  llu m;
  unsigned int k;
  fill_ncr();
  cin >> m >> k;
  if (k == 1) {
    if (m == 1) cout << "1\n";
    return 0;
  }
  llu low = 1, high = 1000000000000000000LL;
  llu mid = (low + high) >> 1, val1, val2;
  while (low <= mid) {
    val1 = countsum(mid << 1, k) - countsum(mid, k);
    if (val1 == m) {
      cout << mid << "\n";
      break;
    } else if (val1 > m) {
      high = mid - 1;
      mid = (low + high) >> 1;
    } else {
      low = mid + 1;
      mid = (low + high) >> 1;
    }
  }
  return 0;
}
