#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();
  }
}

### Prompt

Construct a Cpp code solution to the problem outlined:

One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one".

The girl got interested in the task and she asked you to help her solve it. Sasha knows that you are afraid of large numbers, so she guaranteed that there is an answer that doesn't exceed 1018.

Input

The first line contains two space-separated integers, m and k (0 ≤ m ≤ 1018; 1 ≤ k ≤ 64).

Output

Print the required number n (1 ≤ n ≤ 1018). If there are multiple answers, print any of them.

Examples

Input

1 1


Output

1


Input

3 2


Output

5

### Response

```cpp
#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();
  }
}

```