#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, siz = 1e6 + 5;
long long t, n, y, m, k, a[siz], dp[70][70][2];
long long go(long long ind, long long done, bool free, long long x) {
  if (ind < 0) return (done == k);
  if (dp[ind][done][free] != -1) return dp[ind][done][free];
  long long ret = 0;
  if (free) {
    ret += go(ind - 1, done + 1, free, x);
    ret += go(ind - 1, done, free, x);
  } else {
    bool add = (x & (1LL << ind));
    ret += go(ind - 1, done + add, free, x);
    if (add) ret += go(ind - 1, done, 1, x);
  }
  return dp[ind][done][free] = ret;
}
bool is_ok(long long mid) {
  memset(dp, -1, sizeof dp);
  long long ret = go(63, 0, 0, 2 * mid);
  memset(dp, -1, sizeof dp);
  ret -= go(63, 0, 0, mid);
  return ret <= m;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> m >> k;
  long long l = 1, r = 1e18;
  if (m == k && m == 1) {
    puts("1");
    return 0;
  }
  long long ans;
  while (l <= r) {
    long long mid = l + (r - l) / 2;
    if (is_ok(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << ans << endl;
}
