#include <bits/stdc++.h>
long long a[100][100], k;
using namespace std;
long long solve(long long nu) {
  int cnt = 0;
  long long ans = (__builtin_popcountll(nu) == k);
  for (int i = 63; i >= 0 && cnt <= k; i--) {
    if (((nu >> i) & 1) == 1) {
      ans += a[i][k - cnt];
      cnt++;
    }
  }
  return ans;
}
int main() {
  long long m, hi = 1000000000000000000, lo = 1, mid;
  for (int i = 0; i < 64; i++) a[i][0] = 1;
  for (int i = 1; i <= 64; i++)
    for (int j = 1; j <= i; j++) a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
  cin >> m >> k;
  while (hi >= lo) {
    long long h1;
    mid = (hi + lo) / 2;
    h1 = solve(2 * mid) - solve(mid);
    if (h1 > m)
      hi = mid - 1;
    else if (h1 < m)
      lo = mid + 1;
    else
      break;
  }
  cout << mid;
  return 0;
}
