#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long dp[105][105];
vector<int> bit;
long long cst(long long val) {
  for (int i = 0; i < 105; i++) memset(dp[i], 0, sizeof(dp[i]));
  dp[0][0] = dp[0][1] = 1;
  bit.clear();
  while (val > 0) {
    bit.push_back(val % 2);
    val /= 2;
  }
  int cnt = 1, xx, i = 1;
  bit.pop_back();
  while (!bit.empty()) {
    xx = bit.back();
    bit.pop_back();
    dp[i][0] = 1;
    for (int j = 1; j < 105; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
    }
    if (xx == 0)
      dp[i][cnt + 1] -= 1;
    else
      cnt++;
    i++;
  }
  dp[i][k] = dp[i - 1][k] + dp[i - 1][k - 1];
  dp[i][cnt + 1] -= 1;
  return dp[i][k] - dp[i - 1][k];
}
int main() {
  cin >> m >> k;
  long long st = 1, en = 1e18, mid, cost;
  while (st <= en) {
    mid = (st + en) / 2;
    cost = cst(mid);
    if (cost == m) {
      cout << mid << endl;
      return 0;
    } else if (cost < m) {
      st = mid + 1;
    } else
      en = mid - 1;
  }
}
