#include <bits/stdc++.h>
using namespace std;
inline long long readint() {
  long long a = 0;
  char c = getchar(), f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -f;
  for (; '0' <= c && c <= '9'; c = getchar())
    a = (a << 3) + (a << 1) + (c ^ 48);
  return a * f;
}
const int MaxN = 100;
long long c[MaxN][MaxN];
long long m;
int k;
void input() {
  m = readint(), k = readint();
  for (int i = 0; i < MaxN; ++i)
    for (int j = c[i][0] = 1; j <= i; ++j)
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
}
long long got(long long s) {
  long long res = 0;
  int now = 0;
  for (int i = 62; ~i; --i) {
    if (!(s >> i & 1)) continue;
    res += c[i][k - now];
    if ((++now) > k) break;
  }
  return res;
}
bool check(long long x) { return got(x << 1 | 1) - got(x + 1) >= m; }
void solve() {
  long long L = 1, R = 1e18;
  while (L != R)
    if (check((L + R) >> 1))
      R = (L + R) >> 1;
    else
      L = (L + R) / 2 + 1;
  printf("%lld\n", L);
}
int main() {
  input(), solve();
  return 0;
}
