#include <bits/stdc++.h>
unsigned long long m, k, C[99][99];
void init() {
  for (int i = 0; i < 99; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
  }
}
unsigned long long getct(unsigned long long x) {
  unsigned long long r = 0;
  int cur = 0;
  for (int i = 63; i >= 0; --i) {
    if (x & (1LL << i)) {
      if (k >= cur) r += C[i][k - cur];
      ++cur;
    }
  }
  if (cur == k) ++r;
  return r;
}
unsigned long long ck(unsigned long long x) {
  unsigned long long a = getct(2LL * x);
  unsigned long long b = getct(x);
  return a - b;
}
int main() {
  init();
  scanf("%I64d %I64d", &m, &k);
  unsigned long long l = 1LL, r = 1000000000000000000, md, ans = -1;
  while (l <= r) {
    md = (l + r) >> 1LL;
    unsigned long long ct = ck(md);
    if (ct >= m)
      r = md - 1;
    else
      l = md + 1;
    if (ct == m) {
      ans = md;
      break;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
