#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:300000000")
const long double eps = 1e-9;
const long double pi = acos(-1.0);
const long long inf = 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const long long base = 1000 * 1000 * 1000 + 7;
using namespace std;
long long key[63];
long long f[63][63];
long long m, k;
long long cnt(long long st, long long x, long long y) {
  if (y < 1) return 0;
  long long res = 0;
  long long last = 0;
  for (int j = (st); j <= (62); j++)
    if (key[j] - 1 + key[j] < x)
      res += f[j][y];
    else {
      last = j;
      break;
    }
  if (last == 0) return f[last][y];
  if (key[last] + key[last - 1] <= x) {
    res += cnt(last, x - key[last - 1], y - 1);
    res += f[last - 1][y];
    return res;
  }
  return res + cnt(last - 1, x - key[last - 1], y);
}
long long findA(long long x) {
  long long l = x + 1;
  long long r = x + x;
  long long tmp = cnt(0, r, k) - cnt(0, l - 1, k);
  return tmp;
}
int main() {
  ios_base ::sync_with_stdio(false);
  key[0] = 1;
  for (int i = 1; i < 63; i++) key[i] = key[i - 1] + key[i - 1];
  f[0][1] = 1;
  for (int i = (1); i <= (62); i++) {
    for (int j = (0); j <= (i); j++) f[i][j + 1] += f[i - 1][j];
    for (int j = (0); j <= (i); j++) f[i][j] += f[i - 1][j];
  }
  cin >> m >> k;
  long long left = 1;
  long long right = 1000000000 * 1ll * 1000000000;
  while (right - left > 1) {
    long long middle = (right + left) / 2;
    if (findA(middle) > m)
      right = middle;
    else
      left = middle;
  }
  if (findA(left) == m)
    cout << left;
  else
    cout << right;
  return 0;
}
