#include <bits/stdc++.h>
long long C[65][65] = {{0}};
long long CheckTotal(long long n) {
  long long total = 0;
  while (n) {
    if (n & 1) total++;
    n = n >> 1;
  }
  return total;
}
long long Find(long long num, int k) {
  long long ans = 0;
  if (CheckTotal(num) == k) ans++;
  for (int i = 63; i >= 0 && k >= 0; i--)
    if (((num >> i) & 1)) ans += C[i][k--];
  return ans;
}
int main() {
  C[0][0] = 1;
  for (int i = 1; i <= 63; i++)
    for (int j = 0; j <= i; j++)
      if (j != 0)
        C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
      else
        C[i][j] = C[i - 1][j];
  long long m;
  int k;
  scanf("%lld%d", &m, &k);
  long long l = 1, r = 1000000000000000001LL;
  while (l < r) {
    long long n = (l + r) / 2;
    if (Find(n * 2, k) - Find(n, k) < m)
      l = n + 1;
    else
      r = n;
  }
  printf("%lld\n", l);
  return 0;
}
