#include <bits/stdc++.h>
using namespace std;
long long dp[64][64];
const long long Max_Bit = 63;
long long bcount(long long x) {
  long long Res = 0;
  for (; x; x &= (x - 1)) Res++;
  return Res;
}
long long Solve(long long x, long long k) {
  long long Answer = (k == bcount(x));
  for (long long i = Max_Bit; i >= 0 && k >= 0; i--)
    if (((x >> i) & 1)) Answer += dp[i][k--];
  return Answer;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  dp[0][0] = 1;
  for (long long i = 1; i <= 63; i++)
    for (long long j = 0; j <= i; j++)
      dp[i][j] = dp[i - 1][j] + ((j) ? (dp[i - 1][j - 1]) : 0);
  long long m, k;
  cin >> m >> k;
  long long l, r;
  l = 1;
  r = 2000000000000000000LL;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if ((Solve(2 * mid, k) - Solve(mid, k)) < m) {
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << l << endl;
  return 0;
}
