#include <bits/stdc++.h>
using namespace std;
long long m, k;
long long dp[100][100];
long long dfs(int n, int p) {
  if (n == 0) return (p == 0);
  if (p < 0) return 0;
  if (dp[n][p] != -1) return dp[n][p];
  long long ret = 0;
  ret += dfs(n - 1, p);
  ret += dfs(n - 1, p - 1);
  return dp[n][p] = ret;
}
long long func(long long x) {
  if (x == 0) return 0;
  string s = "";
  long long tmp = x;
  int i = 0;
  while (tmp) {
    int rem = tmp & 1;
    s = s + (char)(rem + '0');
    tmp >>= 1LL;
  }
  for (int i = 0, j = s.length() - 1; i < j; i++, j--) {
    swap(s[i], s[j]);
  }
  long long ans = 0;
  int lmt = k;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 0; j < s[i] - '0'; j++) {
      ans += dfs(s.length() - i - 1, lmt);
    }
    if (s[i] == '1') lmt--;
  }
  if (lmt == 0) ans++;
  return ans;
}
int check(long long x) { return (func(2 * x) - func(x)) >= m; }
int main() {
  memset(dp, -1, sizeof dp);
  cin >> m >> k;
  long long start = 1, end = (long long)1e18 + 1, mid;
  while (start + 1 < end) {
    mid = start + (end - start) / 2;
    if (check(mid)) {
      end = mid;
    } else {
      start = mid;
    }
  }
  for (long long i = start; i <= end; i++) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
