#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
const double EPS = 1e-8;
unsigned long long int C[1010][1010];
void make_C() {
  memset(C, 0, (int)sizeof(C));
  for (int i = 0; i < 1010; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
  }
}
unsigned long long int m;
int k;
unsigned long long int count(string s, int k) {
  if (!k) return 0;
  int d = s.size();
  s.erase(s.end() - 1);
  while (s.size() && *(s.end() - 1) == '0') s.erase(s.end() - 1);
  unsigned long long int ans = C[d - 1][k];
  if (s.size()) ans += count(s, k - 1);
  return ans;
}
string tostring(unsigned long long int k) {
  string ret = k ? "" : "0";
  for (; k; k >>= 1) ret.push_back('0' + (k & 1));
  return ret;
}
unsigned long long int search(unsigned long long int m, int k) {
  unsigned long long int l = 0, r = 1000000000000000000ULL;
  while (l < r - 1) {
    unsigned long long int mid = (l + r) / 2;
    unsigned long long int ret =
        count(tostring(mid * 2 + 1), k) - count(tostring(mid), k);
    if (ret == m) return mid;
    if (ret < m)
      l = mid;
    else
      r = mid;
  }
  return 0;
}
int main() {
  make_C();
  while (cin >> m >> k) {
    cout << search(m, k) << endl;
  }
  return 0;
}
