#include <bits/stdc++.h>
using namespace std;
long long m;
int k;
long long C[65][65];
int main() {
  for (int i = 0; i < 65; ++i) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; ++j) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  }
  cin >> m >> k;
  k--;
  long long ans = 0;
  for (int i = 60; i >= 0; --i) {
    if (k == 0) continue;
    if (m > C[i][k]) {
      ans = ans | (1ll << i);
      m -= C[i][k];
      k--;
    }
  }
  cout << (ans + 1ll) << endl;
  return 0;
}
