#include <bits/stdc++.h>
using namespace std;
long long m, k;
long long c[110][110];
long long C(long long n, long long k) {
  if (k < 0 || k > n) return 0;
  if (n < 0) return 0;
  if (k == 0 || k == n) return 1;
  return c[n][k];
}
long long cal(long long x) {
  int len = 0, bitcnt = 0;
  for (long long t = x; t; t >>= 1) len++;
  long long res = 0;
  for (int i = len - 1; i >= 0; i--) {
    if (x >> i & 1) {
      res += C(i, k - bitcnt);
      bitcnt++;
    }
  }
  return res;
}
bool check(long long mid) { return cal(mid * 2) - cal(mid) >= m; }
int main() {
  for (int i = 0; i <= 100; i++) c[i][0] = 1;
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }
  cin >> m >> k;
  long long l = 1, r = 1000000000000000000LL, mid;
  while (l < r) {
    mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
