#include <bits/stdc++.h>
using namespace std;
long long inf = 4000000000000000000LL;
long long m;
int k;
long long C[65][65];
int main() {
  for (int i = 0; i <= 64; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      if (C[i][j] > inf) C[i][j] = inf + 1;
    }
  }
  cin >> m >> k;
  if (m == 0) {
    printf("1");
    return 0;
  }
  int deg = 59;
  for (long long mm = m;; m = mm) {
    long long n = 0;
    for (int i = deg; m; i--) {
      if (n + (1LL << i) > inf / 4) continue;
      if (C[i + 1][k] > C[i][k] && m >= C[i + 1][k] - C[i][k]) {
        m -= C[i + 1][k] - C[i][k];
        n += 1LL << i;
        k--;
      }
    }
    if (!m) {
      cout << n << endl;
      break;
    }
    deg--;
  }
  return 0;
}
