#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline int read(T& x) {
  x = 0;
  char c = getchar(), f = 1;
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    if (c == -1) return -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  x *= f;
  return 1;
}
template <typename T, typename... Args>
inline int read(T& x, Args&... args) {
  return read(x) + read(args...);
}
template <typename T>
inline int write(T x) {
  if (x < 0) return putchar('-') & write((~x) + 1);
  if (x / 10) return write(x / 10) & putchar(x % 10 | 48);
  return putchar(x | 48);
}
template <typename T>
inline int write(T x, char c) {
  return write(x) + putchar(c);
}
long long m, k;
long long dp[75][75];
int b[75], len;
long long dfs(long long pos, long long tot, long long limit) {
  if (pos > len) return tot == k;
  if (!limit && dp[pos][tot] != -1) return dp[pos][tot];
  int res = limit ? b[len - pos + 1] : 1;
  long long ret = 0;
  for (int i = 0; i <= res; i++)
    ret += dfs(pos + 1, tot + i, limit & (i == res));
  if (!limit) dp[pos][tot] = ret;
  return ret;
}
long long solve(long long x) {
  len = 0;
  while (x) b[++len] = x & 1, x >>= 1;
  memset(dp, -1, sizeof dp);
  return dfs(1, 0, 1);
}
signed main() {
  read(m, k);
  long long l = 1, r = 1e18, ans = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (solve(mid << 1) - solve(mid) >= m)
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  write(ans, '\n');
}
