#include <bits/stdc++.h>
using namespace std;
long long dp[70][70][2];
long long m;
int k, len;
vector<int> digits;
long long solve(int pos, long long cnt, bool sml) {
  if (pos == digits.size()) return cnt == 0;
  if (dp[pos][cnt][sml] != -1) return dp[pos][cnt][sml];
  long long ret = 0;
  ret += solve(pos + 1, cnt, sml || digits[pos] == 1);
  if (cnt > 0 && (sml || digits[pos] == 1)) ret += solve(pos + 1, cnt - 1, sml);
  return dp[pos][cnt][sml] = ret;
}
long long answer(long long v) {
  memset(dp, -1, sizeof dp);
  digits.clear();
  while (v) {
    digits.push_back(v & 1);
    v >>= 1;
  }
  reverse(digits.begin(), digits.end());
  return solve(0, k, 0);
}
long long bs(long long l, long long r) {
  long long mid;
  while (l < r) {
    mid = (l + r) / 2;
    long long v = answer(2 * mid) - answer(mid);
    if (v == m) return mid;
    if (v < m)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return l;
}
int main() {
  cin >> m >> k;
  cout << bs(1, 1000000000000000000LL) << '\n';
  ;
  return 0;
}
