#include <bits/stdc++.h>
using namespace std;
long long dp[100][100];
long long m, k;
long long solve(long long x) {
  long long res = __builtin_popcountll(x) == k;
  long long Count = 0;
  for (int i = 60; 0 <= i; --i) {
    if (!((x >> i) & 1)) continue;
    if (k - Count >= 0) {
      res += dp[i][k - Count];
    }
    Count += 1;
  }
  return res;
}
bool ok(long long x) { return solve(2 * x) - solve(x) >= m; }
int main() {
  for (int i = 0; i <= 61; ++i) {
    dp[i][0] = dp[i][i] = 1;
    for (int j = 1; j < i; ++j) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
  }
  scanf("%lld %lld", &m, &k);
  long long left = 1;
  long long right = 1e18;
  while (left < right) {
    long long mid = (left + right) / 2;
    if (ok(mid))
      right = mid;
    else
      left = mid + 1;
  }
  printf("%lld", left);
  return 0;
}
