#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:LonlyCoder&_Codes")
using namespace std;
long long l, r, mid, ans, m, k;
long long dp[70][70][2], x[70];
long long find(long long now) {
  int len = 0;
  for (; now;) {
    ++len;
    x[len] = now % 2;
    now = now / 2;
  }
  memset(dp, 0x00, sizeof dp);
  dp[len][1][1] = 1;
  for (int i = len - 1; i; --i)
    for (int j = 1; j <= len; ++j) {
      dp[i][j][0] = dp[i + 1][j - 1][0] + dp[i + 1][j][0];
      if (x[i] == 1) {
        dp[i][j][0] += dp[i + 1][j][1];
        dp[i][j][1] = dp[i + 1][j - 1][1];
      } else
        dp[i][j][1] = dp[i + 1][j][1];
    }
  long long ans = dp[1][k][0] + dp[1][k][1];
  memset(dp, 0x00, sizeof dp);
  if (len == 1) return ans;
  dp[1][1][0] = 1;
  if (k == 1) ++ans;
  for (int i = 2; i < len; ++i) {
    for (int j = 1; j <= len; ++j)
      dp[i][j][0] = dp[i - 1][j][0] + dp[i - 1][j - 1][0];
    ans += dp[i][k][0];
  }
  return ans;
}
int main() {
  scanf("%I64d%I64d", &m, &k);
  l = 1;
  r = 1e18 + 1;
  while (l < r) {
    mid = l + r >> 1;
    long long num = find(mid * 2) - find(mid);
    if (num < m)
      l = mid + 1;
    else {
      r = mid;
      ans = mid;
    }
  }
  cout << ans << '\n';
  return 0;
}
