#include <bits/stdc++.h>
using namespace std;
long long f[65][65];
int num[65];
long long m;
int k;
long long dp(int i, int s, bool e) {
  if (i < 0) return s == k;
  if (!e && ~f[i][s]) return f[i][s];
  long long ans = 0;
  int u = e ? num[i] : 1;
  for (int d = 0; d <= u; ++d) ans += dp(i - 1, s + d, e && d == u);
  return e ? ans : f[i][s] = ans;
}
long long solve(long long n) {
  int len = 0;
  for (; n; n >>= 1) num[len++] = n & 1;
  memset(f, -1, sizeof(f));
  return dp(len - 1, 0, 1);
}
int main() {
  long long l, r, mid;
  scanf("%I64d%d", &m, &k);
  l = 1;
  r = 1LL << 60;
  while (l < r) {
    mid = (l + r) / 2;
    if (solve(2 * mid) - solve(mid) < m)
      l = mid + 1;
    else
      r = mid;
  }
  printf("%I64d\n", l);
  return 0;
}
