#include <bits/stdc++.h>
using namespace std;
long long m, k;
long long dp[70][70];
void dpBesaz() {
  dp[0][0] = 1;
  for (int(i) = (0); (i) < (70); ++(i)) dp[i][i] = dp[i][0] = 1LL;
  for (int(i) = (1); (i) < (70); ++(i))
    for (int(j) = (1); (j) < (i); ++(j))
      dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
}
long long count(long long a) {
  long long ret = 0;
  while (a > 0) {
    int bit = __builtin_ctzll(a);
    a -= (1LL << bit);
    int num = k - __builtin_popcountll(a);
    if (num >= 0) ret += dp[bit][num];
  }
  return ret;
}
int main() {
  cin >> m >> k;
  dpBesaz();
  long long lo = 0, hi = (long long)(1e18) + 100;
  while (hi - lo > 1) {
    long long mid = (hi + lo) / 2;
    if (count(2 * mid + 1) - count(mid + 1) < m)
      lo = mid;
    else
      hi = mid;
  }
  cout << hi << endl;
}
