#include <bits/stdc++.h>
using namespace std;
const long long N = 70;
long long ncr[N][N];
long long find(long long n, long long k) {
  long long ans = 0, cnt = k;
  for (long long i = 62; i >= 0; i--) {
    if (n & (1LL << i)) {
      if (cnt >= 0) ans += ncr[i][cnt];
      cnt--;
    }
  }
  if (cnt == 0) ans++;
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long m, k;
  cin >> m >> k;
  ncr[0][0] = 1;
  for (long long i = 1; i < N; i++) {
    ncr[i][0] = 1;
    for (long long j = 1; j <= i; j++) {
      ncr[i][j] = ncr[i - 1][j] + ncr[i - 1][j - 1];
    }
  }
  long long l = 0, r = 1e18;
  while (r > l + 1) {
    long long n = (l + r) / 2;
    if (find(2 * n, k) - find(n, k) >= m)
      r = n;
    else
      l = n;
  }
  cout << r;
}
