#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long m, k;
long long dp[70][70][2];
vector<long long> num;
long long calc(long long pos, long long cnt, long long flag) {
  if (pos == num.size()) {
    if (cnt == k)
      return 1;
    else
      return 0;
  }
  if (dp[pos][cnt][flag] != -1) return dp[pos][cnt][flag];
  long long limit = (flag ? 1 : num[pos]);
  long long ans = 0;
  for (long long i = 0; i <= limit; i++) {
    long long currcnt = cnt;
    if (i != 0) currcnt++;
    long long currflag = flag;
    if (i < num[pos]) currflag = 1;
    ans += calc(pos + 1, currcnt, currflag);
  }
  return dp[pos][cnt][flag] = ans;
}
long long fun(long long x) {
  memset(dp, -1, sizeof(dp));
  num.clear();
  for (long long i = 63; i >= 0; i--) {
    if ((1LL << i) & x)
      num.push_back(1);
    else
      num.push_back(0);
  }
  long long ans = calc(0, 0, 0);
  return ans;
}
void solve() {
  cin >> m >> k;
  long long l = 1, r = 1e18;
  while (l < r) {
    long long mid = (l + r) >> 1;
    long long val = fun(2 * mid) - fun(mid);
    if (val == m) {
      cout << mid << "\n";
      return;
    }
    if (val < m)
      l = mid + 1;
    else
      r = mid - 1;
  }
  if (fun(2 * l) - fun(l) == m)
    cout << l << "\n";
  else
    cout << r << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  for (long long i = 0; i < t; i++) {
    solve();
  }
}
