#include <bits/stdc++.h>
using namespace std;
long long sum[70][70], m, tot = 1, ans = 1;
int main() {
  int K;
  cin >> m >> K, sum[0][0] = 1;
  for (int j = 1; j <= 64; j++) {
    sum[0][j] = sum[0][j - 1];
    for (int i = 1; i <= 64; i++) sum[i][j] = sum[i][j - 1] + sum[i - 1][j - 1];
  }
  for (int i = 63; i >= 0; i--)
    if (sum[K][i + 1] - sum[K][i] + tot <= m)
      tot += sum[K][i + 1] - sum[K][i], ans += 1ll << i, K--;
  return cout << ans << endl, 0;
}
