#include <bits/stdc++.h>
using namespace std;
int getint() {
  unsigned int c;
  int x = 0;
  while (((c = getchar()) - '0') >= 10) {
    if (c == '-') return -getint();
    if (!~c) exit(0);
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while (((c = getchar()) - '0') < 10);
  return x;
}
long long getll() {
  unsigned int c;
  long long x = 0;
  while (((c = getchar()) - '0') >= 10) {
    if (c == '-') return -getll();
    if (!~c) exit(0);
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while (((c = getchar()) - '0') < 10);
  return x;
}
const int MAXN = 66;
long long bn[MAXN + 1][MAXN + 1];
void make_bn(int n) {
  for (int i = 0; i <= n; i++) {
    bn[i][0] = bn[i][i] = 1;
    for (int j = 1; j < i; j++) bn[i][j] = bn[i - 1][j - 1] + bn[i - 1][j];
  }
}
long long m;
int k, add;
unsigned long long count(unsigned long long now, int need) {
  if (need == 0) {
    if (now == 0) return 1;
    return 0;
  }
  if (now == 0) return 0;
  int under_bits;
  for (under_bits = 0; (1ULL << (under_bits + 1)) <= now; under_bits++)
    ;
  return bn[under_bits][need] + count(now - (1ULL << under_bits), need - 1);
}
int main() {
  int i, j, tcc, tc = 1 << 28;
  make_bn(65);
  for (tcc = 0; tcc < tc; tcc++) {
    m = getll(), k = getint();
    unsigned long long a = 1, b = 1e18 + 12, mid;
    for (; a <= b;) {
      mid = a + b >> 1;
      unsigned long long num = count(mid * 2, k) - count(mid, k);
      if (num == m) {
        b = mid;
        break;
      }
      if (num > m) {
        b = mid - 1;
      } else {
        a = mid + 1;
      }
    }
    cout << b << endl;
  }
  return 0;
}
