#include <bits/stdc++.h>
using namespace std;
int k;
long long l, r, m, C[65][65];
inline long long f(long long x) {
  long long ret = 0;
  int cnt = 0, w;
  for (int j = w = 63 - __builtin_clzll(x); ~j && k >= cnt; --j)
    if (x & 1ll << j) ret += C[j][k - cnt], ++cnt;
  if (__builtin_popcountll(x) == k) ++ret;
  return ret;
}
int main() {
  scanf("%I64d%d", &m, &k);
  for (int i = 0; i <= 64; ++i) {
    *C[i] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
  for (l = 1, r = 1000000000000000000ll; l + 1 < r;) {
    long long mid = l + r >> 1;
    if (f(mid << 1) - f(mid) > m)
      r = mid;
    else
      l = mid;
  }
  printf("%I64d\n", l);
}
