#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
template <class T>
inline T isqrt(T k) {
  T r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
template <class T>
inline T icbrt(T k) {
  T r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return (int)fpow(a, p - 2, p); }
const int maxn = 64;
long long m, k;
int a[maxn];
long long dp[maxn][maxn][2];
long long calc(int pos, int cnt, int fa) {
  if (pos == maxn) return cnt == k;
  long long& res = dp[pos][cnt][fa];
  if (~res) return res;
  res = 0;
  if (cnt > k) return res;
  int lo = 0, hi = 1;
  if (!fa) chkmin(hi, a[pos]);
  for (int i = (lo); i < (hi + 1); i++) {
    res += calc(pos + 1, cnt + i, fa | (i < a[pos]));
  }
  return res;
}
long long ff(long long n, int k) {
  memset(a, 0, sizeof(a));
  int ptr = maxn - 1;
  while (n) {
    a[ptr--] = n & 1;
    n >>= 1;
  }
  memset(dp, -1, sizeof(dp));
  return calc(0, 0, 0);
}
void solve() {
  cin >> m >> k;
  for (int i = (0); i < (100); i++) {
    long long l = i > 0 ? 0 : 1, r = LINF / 100;
    while (l < r) {
      long long mid = (l + r) >> 1;
      long long n = mid * 100 + i;
      if (ff(n + n, k) - ff(n, k) < m) {
        l = mid + 1;
      } else {
        r = mid;
      }
    }
    long long n = l * 100 + i;
    if (n <= LINF && ff(n + n, k) - ff(n, k) == m) {
      cout << n << "\n";
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("in.txt", "r")) {
    freopen("in.txt", "r", stdin);
  }
  solve();
  cerr << "\n" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

### Prompt

Generate a Cpp solution to the following problem:

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;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
template <class T>
inline T isqrt(T k) {
  T r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
template <class T>
inline T icbrt(T k) {
  T r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return (int)fpow(a, p - 2, p); }
const int maxn = 64;
long long m, k;
int a[maxn];
long long dp[maxn][maxn][2];
long long calc(int pos, int cnt, int fa) {
  if (pos == maxn) return cnt == k;
  long long& res = dp[pos][cnt][fa];
  if (~res) return res;
  res = 0;
  if (cnt > k) return res;
  int lo = 0, hi = 1;
  if (!fa) chkmin(hi, a[pos]);
  for (int i = (lo); i < (hi + 1); i++) {
    res += calc(pos + 1, cnt + i, fa | (i < a[pos]));
  }
  return res;
}
long long ff(long long n, int k) {
  memset(a, 0, sizeof(a));
  int ptr = maxn - 1;
  while (n) {
    a[ptr--] = n & 1;
    n >>= 1;
  }
  memset(dp, -1, sizeof(dp));
  return calc(0, 0, 0);
}
void solve() {
  cin >> m >> k;
  for (int i = (0); i < (100); i++) {
    long long l = i > 0 ? 0 : 1, r = LINF / 100;
    while (l < r) {
      long long mid = (l + r) >> 1;
      long long n = mid * 100 + i;
      if (ff(n + n, k) - ff(n, k) < m) {
        l = mid + 1;
      } else {
        r = mid;
      }
    }
    long long n = l * 100 + i;
    if (n <= LINF && ff(n + n, k) - ff(n, k) == m) {
      cout << n << "\n";
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("in.txt", "r")) {
    freopen("in.txt", "r", stdin);
  }
  solve();
  cerr << "\n" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

```