#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const double eps = 1e-10;
const int MAXN = 1000010;
long long m;
int k;
long long dp[70][70];
int bit[70];
long long dfs(int pos, int num, bool limit) {
  if (pos == -1) return num == k;
  if (!limit && ~dp[pos][num]) return dp[pos][num];
  int end = limit ? bit[pos] : 1;
  long long ans = 0;
  for (int i = 0; i <= end; i++) {
    if (i)
      ans += dfs(pos - 1, num + 1, limit && (i == end));
    else
      ans += dfs(pos - 1, num, limit && (i == end));
  }
  if (!limit) dp[pos][num] = ans;
  return ans;
}
long long get(long long x) {
  if (x == 0) return 0;
  int len = 0;
  while (x) {
    bit[len++] = x % 2;
    x /= 2;
  }
  return dfs(len - 1, 0, 1);
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> m >> k;
  long long l, r;
  l = 1, r = 1LL * 1e18;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long x = get(mid * 2) - get(mid);
    if (x >= m)
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
