#include <bits/stdc++.h>
using namespace std;
long long m, k;
long long com[111][111], mu[111];
long long get(long long x, long long y) { return (x >> y) & 1; }
long long check(long long s) {
  long long ans = 0;
  int pivot = 0, value;
  for (int i = 0; i <= 63; i++)
    if (get(s, i)) pivot = i;
  value = k;
  for (int i = pivot; i >= 0; i--)
    if (get(s, i)) {
      ans += com[i][value];
      value--;
    }
  if (value == 0) ans++;
  return ans;
}
void init() {
  for (int i = 0; i <= 63; i++)
    for (int j = 0; j <= 63; j++)
      if (i < j)
        com[i][j] = 0;
      else if ((i == j) || (j == 0))
        com[i][j] = 1;
      else
        com[i][j] = com[i - 1][j - 1] + com[i - 1][j];
}
int main() {
  cin >> m >> k;
  init();
  mu[0] = 1;
  for (int i = 1; i <= k; i++) mu[i] = mu[i - 1] * 2;
  long long value = 0;
  int ncount = 0;
  for (int i = 1; i <= k; i++) value += mu[i - 1];
  srand(time(NULL));
  while (true) {
    long long low = 1, high = 1000000000000000000ll, mid;
    ncount++;
    if (ncount > 1) high = rand() % (high / value) * value;
    if (ncount <= 11)
      if (ncount > 1) high = value * (ncount - 1);
    high = max(high, (long long)1);
    while (low + 1 < high) {
      mid = (low + high) / 2;
      if (check(mid * 2) - check(mid) == m) {
        cout << mid;
        return 0;
      }
      if (check(mid * 2) - check(mid) < m)
        low = mid;
      else
        high = mid;
    }
    if (check(low * 2) - check(low) == m) {
      cout << low;
      break;
    } else if (check(high * 2) - check(high) == m) {
      cout << high;
      break;
    }
  }
}
