#include <bits/stdc++.h>
using namespace std;
const int MAXN = 63;
long long m, k;
long long C[MAXN][MAXN];
long long Read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x * 10) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
void Put1(long long x) {
  if (x > 9) Put1(x / 10);
  putchar(x % 10 ^ 48);
}
void Put(long long x, char c = -1) {
  if (x < 0) putchar('-'), x = -x;
  Put1(x);
  if (c >= 0) putchar(c);
}
template <typename T>
T Max(T x, T y) {
  return x > y ? x : y;
}
template <typename T>
T Min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
T Abs(T x) {
  return x < 0 ? -x : x;
}
int a[MAXN];
long long Get(long long x) {
  int len = 0, yi = 0;
  long long ret = 0;
  while (x) a[++len] = x & 1, x >>= 1;
  for (int i = len; i >= 1; --i) {
    if (a[i] && i - 1 >= k - yi && k >= yi) ret += C[i - 1][k - yi];
    yi += a[i];
  }
  return ret;
}
bool check(long long n) {
  if (Get(n << 1) - Get(n) >= m) return 1;
  return 0;
}
void pre() {
  C[0][0] = 1;
  for (int i = 1; i <= 62; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
}
int main() {
  pre();
  m = Read();
  k = Read();
  long long l = 1, r = 1e18, ans = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  Put(ans);
  return 0;
}
