#include <bits/stdc++.h>
using namespace std;
const long long mxbit = 63;
long long C[mxbit + 1][mxbit + 1];
long long bcount(long long x) {
  long long res = 0;
  for (; x != 0; x &= (x - 1)) {
    res++;
  }
  return res;
}
long long solve(long long x, long long k) {
  long long ans = (k == bcount(x));
  for (long long i = mxbit; i >= 0 && k >= 0; i--) {
    if (((x >> i) & 1)) {
      ans += C[i][k--];
    }
  }
  return ans;
}
signed main() {
  C[0][0] = 1;
  for (long long i = 1; i <= mxbit; i++) {
    for (long long j = 0; j <= i; j++) {
      C[i][j] = C[i - 1][j] + ((j) ? (C[i - 1][j - 1]) : 0);
    }
  }
  long long count, k;
  scanf("%lld%lld", &count, &k);
  long long l = 1, r = 2000000000000000000 / 2;
  while (l < r) {
    long long mid = l + (r - l) / 2;
    if (solve(mid * 2, k) - solve(mid, k) < count) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  printf("%lld\n", l);
  return 0;
}
