#include <bits/stdc++.h>
using namespace std;
long long int dp[65][65];
long long int solve(long long int n, long long int k) {
  long long int num = n;
  vector<int> v;
  while (num) {
    v.push_back(num % 2);
    num /= 2;
  }
  long long int ret = 0, cnt = 0;
  for (int i = v.size() - 1; i >= 0; i--) {
    if (v[i] == 1) {
      if (i + cnt >= k && k - cnt >= 0) ret += dp[i][k - cnt];
      cnt++;
    }
  }
  if (cnt == k) ret++;
  return ret;
}
int main() {
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 1; i < 65; i++) {
    dp[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
    }
  }
  long long int l = 1, r = 1e18, m, k;
  cin >> m >> k;
  while (l < r) {
    long long int mid = (l + r) / 2;
    long long int val = solve(2 * mid, k);
    val -= solve(mid, k);
    if (val < m) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  cout << l << endl;
  return 0;
}
