#include <bits/stdc++.h>
template <class _, class __>
bool checkmax(_ &a, __ b) {
  return a < b ? a = b, true : false;
}
template <class _, class __>
bool checkmin(_ &a, __ b) {
  return a > b ? a = b, true : false;
}
using namespace std;
long long m, k;
int bit[70];
long long dp[70][205];
long long dfs(int len, int sum, bool e) {
  if (!len) return sum == 64;
  if (!e && ~dp[len][sum]) return dp[len][sum];
  long long res = 0;
  int up = e ? bit[len] : 1;
  for (int i = (0), i_end_ = (up); i <= i_end_; ++i) {
    res += dfs(len - 1, sum - i, e & (i == up));
  }
  return e ? res : dp[len][sum] = res;
}
long long solve(long long x) {
  int len = 0;
  memset(dp, -1, sizeof(dp));
  memset(bit, 0, sizeof(bit));
  while (x) {
    bit[++len] = x & 1;
    x >>= 1;
  }
  return dfs(len, k + 64, true);
}
bool check(long long x) { return solve(x << 1) - solve(x) >= m; }
int main() {
  cin >> m >> k;
  long long L = 1, R = 1e18, res = R;
  while (L <= R) {
    long long mid = (L + R) >> 1;
    if (check(mid)) {
      R = mid - 1;
      res = mid;
    } else
      L = mid + 1;
  }
  printf("%lld\n", (long long)res);
  return EXIT_SUCCESS;
}
