#include <bits/stdc++.h>
using namespace std;
long long m;
int k;
long long c[65][65];
void calCombination();
long long cal(long long);
long long f(long long);
int main() {
  calCombination();
  cin >> m >> k;
  long long lo = 1;
  long long hi = 1e18;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    long long ret = cal(mid);
    if (ret == m) {
      cout << mid << endl;
      return 0;
    }
    if (ret < m) {
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  return 0;
}
long long f(long long x) {
  string s = "";
  while (x > 0) {
    s = char(x % 2 + '0') + s;
    x = x / 2;
  }
  int zero = 0;
  long long ret = c[k][s.length()];
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      if (zero + 1 <= k) {
        int rem = k - (zero + 1);
        int l = s.length() - (i + 1);
        ret = ret - c[rem][l];
      }
    } else {
      zero++;
    }
  }
  return ret;
}
long long cal(long long mid) { return (f(2 * mid) - f(mid)); }
void calCombination() {
  int size = 64;
  for (int i = 0; i <= size; i++) c[0][i] = 1;
  for (int i = 1; i <= size; i++)
    for (int j = i; j <= size; j++) {
      c[i][j] = (c[i][j - 1] + c[i - 1][j - 1]);
    }
}
