#include <bits/stdc++.h>
using namespace std;
const double EPS = 0.0000001;
const double PI = acos(-1);
const long long INFLL = 0x7FFFFFFFFFFFFFFF;
const int INF = 0x7FFFFFFF;
template <typename T>
inline void next(T &num) {
  char c;
  num = 0;
  do {
    c = getchar_unlocked();
  } while (c != EOF && c == ' ' && c == '\n' && c == '\t');
  int sign = (c == '-' ? -1 : 1);
  if (c != '-') num += (c - '0');
  while ((c = getchar_unlocked()) != EOF && c != '\n' && c != '\t' &&
         c != ' ') {
    num *= 10;
    num += (c - '0');
  }
  num *= sign;
}
inline string getstr() {
  string str;
  char k;
  while ((k = getchar_unlocked()) == ' ' || k == '\n') {
    k = getchar_unlocked();
    if (k == ' ' || k == '\n')
      continue;
    else
      break;
  }
  while ((k = getchar_unlocked()) != EOF && k != '\n' && k != '\t' &&
         k != '\v' && k != '\0' && k != ' ')
    str.push_back(k);
  return str;
}
long long n, k, dp[70][70];
long long solve(long long n, long long k) {
  if (!k) return 1;
  int tmp = __builtin_popcountll(n);
  long long res = (tmp == k);
  for (int i = 0; (1LL << i) <= n && tmp; i++) {
    if (n & (1LL << i)) {
      if (0 <= k - tmp + 1 && k - tmp + 1 <= (1LL << i))
        res += dp[i][k - tmp + 1];
      n -= (1LL << i);
      tmp--;
    }
  }
  return res;
}
int main() {
  next(n);
  next(k);
  for (int i = int(0), _b = int(64); i <= _b; i++) {
    for (int j = int(0), _b = int(i); j <= _b; j++) {
      if (!j)
        dp[i][j] = 1;
      else
        dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
    }
  }
  long long L = 1, R = 1e18, res = 0;
  while (L <= R) {
    long long mid = (L + R) >> 1;
    long long ans = solve(2ll * mid, k) - solve(mid, k);
    if (ans > n) {
      R = mid - 1;
    } else {
      L = mid + 1;
      res = mid;
    }
  }
  printf("%I64d", res);
  getchar_unlocked();
  return 0;
}
