#include <bits/stdc++.h>
using namespace std;
long long int choose[70][70];
long long int ans_k(long long int n, long long int k) {
  long long int a[70], d, l, ans, c1, i;
  d = n;
  c1 = 0, ans = 0, l = 0;
  while (d > 0) {
    a[c1] = d % 2;
    d /= 2, c1 += 1;
  }
  for (i = c1 - 1; i >= 0; i--) {
    if (a[i] && k >= 0) {
      ans += choose[i][k];
      k -= 1;
    }
  }
  return ans;
}
long long int bin_search(long long int l, long long int r, long long int m,
                         long long int k) {
  long long int mid, d, d1;
  while (l <= r) {
    mid = (l + r) / 2;
    d = ans_k(2 * mid, k);
    d1 = ans_k(mid, k);
    if (d - d1 == m)
      return mid;
    else if (d - d1 > m)
      r = mid - 1;
    else
      l = mid + 1;
  }
  return -1;
}
int main() {
  long long int n, m, k, d, i, j;
  scanf("%lld%lld", &m, &k);
  n = 1000000000000000000LL;
  choose[0][0] = 1;
  for (i = 1; i < 65; i++) {
    choose[i][0] = 1, choose[i][i] = 1;
    for (j = 1; j < i; j++) {
      choose[i][j] = choose[i - 1][j] + choose[i - 1][j - 1];
    }
  }
  d = bin_search(1, n, m, k);
  printf("%lld\n", d);
  return 0;
}
