#include <bits/stdc++.h>
using namespace std;
int up[70];
long long C[70][70];
void init() {
  for (int i = 0; i <= 66; i++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j++) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
      if (C[i][j] > 1e18) C[i][j] = 1e18, C[i][j]++;
    }
  }
}
long long dfs(bool fg, int pos, int len, int need) {
  if (need == 0) return 1;
  if (pos == len + 1) return 0;
  int res = len - pos + 1;
  if (res < need) return 0;
  if (fg) {
    return C[res][need];
  }
  if (up[pos] == 1) {
    long long res = 0;
    res += dfs(1, pos + 1, len, need);
    res += dfs(0, pos + 1, len, need - 1);
    res = min(res, (long long)(1e18) + 1ll);
    return res;
  }
  return dfs(0, pos + 1, len, need);
}
long long check(long long n, long long k) {
  long long mul = 1;
  while (mul * 2 <= n) mul *= 2;
  int len = 0;
  for (; mul; mul /= 2) {
    up[++len] = n / mul;
    n %= mul;
  }
  long long ct_n = dfs(0, 1, len, k);
  up[++len] = 0;
  long long ct_2n = dfs(0, 1, len, k);
  return ct_2n - ct_n;
}
int main() {
  init();
  long long m, k;
  scanf("%lld%lld", &m, &k);
  long long l = 1, r = 1e18;
  if (check(l, k) == m) return 0 * printf("%lld\n", l);
  if (check(r, k) == m) return 0 * printf("%lld\n", r);
  while (r - l > 1) {
    long long mid = l + r >> 1;
    if (check(mid, k) >= m)
      r = mid;
    else
      l = mid;
  }
  printf("%lld\n", r);
}
