#include <bits/stdc++.h>
using namespace std;
long long n, m, K;
long long a[105], f[105][105];
long long dfs(long long len, long long cnt, bool limit) {
  if (len == 0) return cnt == K;
  if (!limit && f[len][cnt] != -1) return f[len][cnt];
  long long mx = limit ? a[len] : 1;
  long long res = 0;
  for (long long i = 0; i <= mx; i++)
    res += dfs(len - 1, cnt + i, limit && i == mx);
  if (!limit) f[len][cnt] = res;
  return res;
}
long long solve(long long x) {
  long long k = 0;
  while (x) a[++k] = x & 1, x >>= 1;
  return dfs(k, 0, 1);
}
bool check(long long x) {
  long long res1 = solve(2 * x), res2 = solve(x);
  return res1 - res2 >= m;
}
signed main() {
  scanf("%lld%lld", &m, &K);
  memset(f, -1, sizeof(f));
  long long l = 1, r = 1e18, ans = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
