#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
const int INF = 0x3f3f3f3f;
const long long MOD = 1e9 + 7;
long long m;
int K;
long long C(int n, int m) {
  if (n < m) return 0;
  long long ans = 1;
  for (int i = (0), i_end_ = (m); i < i_end_; ++i)
    ans = ans * (n - i) / (i + 1);
  return ans;
}
bool ok(long long n) {
  int c = 0;
  long long ans = 0;
  for (int i = 62; i >= 0; i--) {
    if (n & (1LL << i)) {
      ans += C(i + 1, K - c) - C(i, K - c);
      c++;
      if (ans >= m) return true;
    }
  }
  return false;
}
int main() {
  cin >> m >> K;
  long long lb = -1, ub = 1e18 + 10;
  while (ub - lb > 1) {
    long long mid = (lb + ub) >> 1;
    if (ok(mid))
      ub = mid;
    else
      lb = mid;
  }
  printf("%lld\n", ub);
}
