#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 29;
long long dp[70][70];
long long count(long long n, int k) {
  long long ans = 0;
  for (int i = 61; i > -1; --i) {
    if ((n >> i) & 1) {
      if (i)
        ans += dp[i - 1][k];
      else if (k == 0)
        ans++;
      --k;
      if (k < 0) break;
    }
  }
  return ans;
}
int main() {
  long long m;
  int k;
  scanf("%I64d%d", &m, &k);
  dp[0][0] = 1;
  dp[0][1] = 1;
  for (int i = 1; i < 62; ++i) {
    for (int j = 0; j <= k; ++j) {
      dp[i][j] += dp[i - 1][j];
      dp[i][j + 1] += dp[i - 1][j];
    }
  }
  long long left = 1, right = 1000000000000000000LL, mid;
  while (left <= right) {
    mid = (left + right) / 2;
    long long t = count(mid * 2 + 1, k) - count(mid + 1, k);
    if (t > m)
      right = mid - 1;
    else if (t < m)
      left = mid + 1;
    else
      break;
  }
  printf("%I64d", mid);
}
