#include <bits/stdc++.h>
using namespace std;
long long m, k, l, r, mid;
long long memo[110][110];
long long C(int r, int n) {
  if (r < 0) return 0;
  if (r > n) return 0;
  if (r == n) return 1;
  if (r == 0) return 1;
  if (memo[r][n] != -1) return memo[r][n];
  return memo[r][n] = C(r - 1, n - 1) + C(r, n - 1);
}
long long calc(long long x) {
  long long p = __builtin_popcountll(x);
  long long cur = 0;
  long long ret = 0;
  if (p == k) ret = 1;
  while (x) {
    if (x & 1) {
      p--;
      ret += C(k - p, cur);
    }
    cur++;
    x >>= 1;
  }
  return ret;
}
int main() {
  memset(memo, -1, sizeof(memo));
  cin >> m >> k;
  l = 0, r = 1e18 + 1;
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (calc(2 * mid) - calc(mid) >= m)
      r = mid;
    else
      l = mid;
  }
  cout << r;
}
