#include <bits/stdc++.h>
using namespace std;
int bitCount(long long int n) {
  int ret = 0;
  while (n != 0) {
    n &= (n - 1);
    ret++;
  }
  return ret;
}
long long int Com[63 + 5][63 + 5] = {0};
long long int f(long long int n, int k) {
  long long int ans = 0;
  if (bitCount(n) == k) ans = 1;
  for (int i = 63; i >= 0 && k >= 0; i--) {
    if (((n >> i) & 1)) {
      ans += Com[i][k];
      k--;
    }
  }
  return ans;
}
int main() {
  Com[0][0] = 1;
  for (int i = 1; i <= 63; i++) {
    for (int j = 0; j <= i; j++) {
      if (j > 0)
        Com[i][j] = Com[i - 1][j] + Com[i - 1][j - 1];
      else
        Com[i][j] = Com[i - 1][j];
    }
  }
  int k;
  long long int m;
  cin >> m >> k;
  long long int lo = 1, hi = 2000000000000000000LL / 2;
  while (lo < hi) {
    long long int mid = lo + (hi - lo) / 2;
    if (f(mid * 2, k) - f(mid, k) >= m)
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << lo << endl;
  return 0;
}
