#include <bits/stdc++.h>
using namespace std;
long long c[100][100], p[100];
int main() {
  long long m;
  int k;
  cin >> m >> k;
  k--;
  int n = 64;
  c[0][0] = 1;
  for (int i = 1; i < n; ++i) {
    c[i][0] = 1;
    for (int j = 1; j <= i; ++j) {
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }
  }
  p[0] = 1;
  for (int i = 1; i < n; ++i) p[i] = p[i - 1] * 2;
  long long ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (m > c[i][k]) {
      m -= c[i][k];
      k--;
      ans += p[i];
    }
  }
  cout << ans + 1 << endl;
  return 0;
}
