#include <bits/stdc++.h>
using namespace std;
unsigned long long m;
int k;
int second[65];
unsigned long long dp[65][2][69];
unsigned long long cal(unsigned long long n) {
  unsigned long long t = -1;
  if (n == t) return 0;
  for (int i = 0; i < 64; i++) second[i] = n & 1, n >>= 1;
  memset(dp, 0, sizeof(dp));
  dp[64][0][0] = 1;
  for (int i = 64; i > 0; i--)
    for (int j = 0; j <= k; j++) {
      if (dp[i][0][j]) {
        if (second[i - 1]) {
          dp[i - 1][0][j + 1] += dp[i][0][j];
          dp[i - 1][1][j] += dp[i][0][j];
        } else
          dp[i - 1][0][j] += dp[i][0][j];
      }
      if (dp[i][1][j]) {
        dp[i - 1][1][j] += dp[i][1][j];
        dp[i - 1][1][j + 1] += dp[i][1][j];
      }
    }
  return dp[0][0][k] + dp[0][1][k];
}
unsigned long long sol() {
  unsigned long long l = 0, r = (unsigned long long)1e18 + 5, mid;
  ;
  while (l <= r) {
    mid = (l + r) >> 1;
    unsigned long long v = cal(mid << 1) - cal(mid);
    if (v == m)
      return mid;
    else if (v > m)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return r;
}
int main() {
  cin >> m >> k;
  if (m == 0) return puts("1"), 0;
  cout << sol() << endl;
  return 0;
}
