#include <bits/stdc++.h>
using namespace std;
long long m, k, dp[70], p, d, ans, l, r = 1e18 + 2, mid;
string s1, s2;
string binary(long long m, long long k) {
  string g = "";
  for (long long i = 0; i < k; i++) {
    g += char((m % 2) + '0'), m = m / 2;
  }
  return g;
}
bool check(long long x) {
  long long cx = x, t = 0;
  d = 0, ans = 0;
  for (long long i = 0; i < 68; i++) dp[i] = 0;
  while (cx) {
    cx /= 2;
    t++;
  }
  s1 = binary(x + 1, t);
  for (long long i = t - 1; i >= 0; i--) {
    if (s1[i] == '0') {
      for (long long j = k; j >= 1; j--) dp[j] += dp[j - 1];
      dp[d + 1]++;
    } else {
      for (long long j = k; j >= 1; j--) dp[j] += dp[j - 1];
      d++;
    }
  }
  dp[d]++;
  ans = dp[k];
  s1 = binary(2 * x, t + 1);
  for (long long i = 0; i < 65; i++) dp[i] = 0;
  d = 1;
  for (long long i = t - 1; i >= 0; i--) {
    if (s1[i] == '0') {
      for (long long j = k; j >= 1; j--) {
        dp[j] += dp[j - 1];
      }
    } else {
      for (long long j = k; j >= 1; j--) {
        dp[j] += dp[j - 1];
      }
      dp[d]++;
      d++;
    }
  }
  dp[d]++;
  long long o = 0;
  x++;
  while (x) {
    o += x % 2;
    x /= 2;
  }
  if (o == 1) ans = 0;
  return (ans + dp[k] <= m);
}
int main() {
  cin >> m >> k;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (check(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l << endl;
}
