#include <bits/stdc++.h>
using namespace std;
long long n, d[101][101][2], d2[101][101];
int k, a[101];
long long get(long long x) {
  int sz = 0;
  long long cur = x;
  while (cur) {
    a[++sz] = cur % 2;
    cur >>= 1;
  }
  reverse(a + 1, a + sz + 1);
  for (int i = 1; i <= sz; ++i)
    for (int j = 0; j <= sz; ++j) d[i][j][0] = d[i][j][1] = 0;
  d[1][1][1] = 1;
  for (int i = 1; i < sz; ++i)
    for (int j = 0; j <= sz; ++j)
      for (int eq = 0; eq < 2; ++eq)
        if (!eq) {
          d[i + 1][j][eq] += d[i][j][eq];
          if (j < sz) d[i + 1][j + 1][eq] += d[i][j][eq];
        } else {
          if (a[i + 1] == 1) {
            d[i + 1][j][0] += d[i][j][eq];
            d[i + 1][j + 1][1] += d[i][j][eq];
          } else
            d[i + 1][j][eq] += d[i][j][eq];
        }
  long long ans = 0;
  for (int i = k; i < sz; ++i) ans += d2[i][k];
  ans += d[sz][k][0] + d[sz][k][1];
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  long long l = 0, r = (long long)1e18 + 1;
  d2[1][1] = 1;
  for (int i = 1; i < 64; ++i)
    for (int j = 0; j <= 64; ++j) {
      d2[i + 1][j] += d2[i][j];
      if (j < 64) d2[i + 1][j + 1] += d2[i][j];
    }
  while (r - l > 1) {
    long long m = (l + r) >> 1;
    if (get(2 * m) - get(m) >= n)
      r = m;
    else
      l = m;
  }
  cout << r;
}
