#include <bits/stdc++.h>
using namespace std;
long long C[64][64], m, k = 1;
long long f1(long long x) {
  long long ret = 0, cnt = 0;
  for (long long i = 63; i >= 0 && (k - cnt) >= 0; i--) {
    if ((x >> i) & 1) {
      ret += C[i][k - cnt];
      cnt++;
    }
  }
  cnt = 0;
  for (long long i = 63; i >= 0 && (k - cnt) >= 0; i--) {
    if ((x >> i) & 1) {
      cnt++;
    }
  }
  if (cnt == k) ret++;
  return ret;
}
long long f(long long x) {
  long long ret = f1(2 * x) - f1(x);
  return ret;
}
int main() {
  int i, j;
  for (i = 0; i < 64; i++) C[i][0] = 1;
  for (i = 1; i < 64; i++) {
    for (j = 1; j <= i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
  cin >> m >> k;
  long long lo = 0, hi = (long long)1e18;
  while (hi - lo > 1) {
    long long mid = (hi + lo) / 2;
    if (f(mid) <= m)
      lo = mid;
    else
      hi = mid;
  }
  cout << lo << endl;
  return 0;
}
