#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
const long long MOD = 1000000000 + 7;
const long long INF = 1000000000000000000;
const long long LOG = 63;
long long add(long long x, long long y) { return min((x + y), INF); }
long long m, k, nCr[N][N];
long long calc(long long x) {
  int cnt = 0;
  long long res = 0;
  for (int i = LOG - 1; i >= 0; i--) {
    if (x & (1ll << i)) {
      if (k - cnt < 0) continue;
      res = add(res, nCr[i][k - cnt]);
      cnt++;
    }
  }
  if (cnt == k) res++;
  return res;
}
bool isval(long long x) {
  long long res = calc(2 * x) - calc(x);
  return res >= m;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> m >> k;
  nCr[0][0] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0)
        nCr[i][j] = 1;
      else
        nCr[i][j] = add(nCr[i - 1][j - 1], nCr[i - 1][j]);
    }
  }
  long long l = 0, r = INF;
  while (r - l > 1) {
    long long mid = (r + l) / 2;
    if (isval(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r;
  return 0;
}
