#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  unsigned long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T bpow(T p, T e) {
  unsigned long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
long long int n, rs, x, y;
long long int q, cs;
long long int bl[2][2][65][65];
long long int p[2][2][65][65];
long long int dp(bool bg, bool sm, int i, int j) {
  if (i == 64) {
    if (j == q) return 1LLU;
    return 0LLU;
  }
  long long int &pr = p[bg][sm][i][j];
  if (bl[bg][sm][i][j] == cs) return pr;
  bl[bg][sm][i][j] = cs;
  pr = 0LLU;
  char mn, mx;
  bool nbg, nsm;
  if (bg == 1)
    mn = 0;
  else if (x & (1LLU << (63 - i)))
    mn = 1;
  else
    mn = 0;
  if (sm == 1)
    mx = 1;
  else if (y & (1LLU << (63 - i)))
    mx = 1;
  else
    mx = 0;
  for (int k = mn; k <= mx; k++) {
    nbg = (bg == 1) ? 1 : (k > mn);
    nsm = (sm == 1) ? 1 : (k < mx);
    pr += dp(nbg, nsm, i + 1, j + (k == 1));
  }
  return pr;
}
int main() {
  long long int t, i, j, n;
  long long int l, h, md;
  cs = 1;
  cin >> n >> q;
  l = 1LLU;
  h = 1000000000000000000LLU;
  while (l <= h) {
    md = ((l + h) >> 1LLU);
    x = md + 1LLU;
    y = (md << 1LLU);
    x = dp(0, 0, 0, 0);
    cs++;
    if (x == n) {
      printf("%llu\n", md);
      return 0;
    }
    if (x <= n) {
      l = md + 1LLU;
    } else
      h = md - 1LLU;
  }
  printf("0\n");
  return 0;
}

### Prompt

Please create a solution in CPP 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;
template <class T>
inline T bigmod(T p, T e, T M) {
  unsigned long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T bpow(T p, T e) {
  unsigned long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
long long int n, rs, x, y;
long long int q, cs;
long long int bl[2][2][65][65];
long long int p[2][2][65][65];
long long int dp(bool bg, bool sm, int i, int j) {
  if (i == 64) {
    if (j == q) return 1LLU;
    return 0LLU;
  }
  long long int &pr = p[bg][sm][i][j];
  if (bl[bg][sm][i][j] == cs) return pr;
  bl[bg][sm][i][j] = cs;
  pr = 0LLU;
  char mn, mx;
  bool nbg, nsm;
  if (bg == 1)
    mn = 0;
  else if (x & (1LLU << (63 - i)))
    mn = 1;
  else
    mn = 0;
  if (sm == 1)
    mx = 1;
  else if (y & (1LLU << (63 - i)))
    mx = 1;
  else
    mx = 0;
  for (int k = mn; k <= mx; k++) {
    nbg = (bg == 1) ? 1 : (k > mn);
    nsm = (sm == 1) ? 1 : (k < mx);
    pr += dp(nbg, nsm, i + 1, j + (k == 1));
  }
  return pr;
}
int main() {
  long long int t, i, j, n;
  long long int l, h, md;
  cs = 1;
  cin >> n >> q;
  l = 1LLU;
  h = 1000000000000000000LLU;
  while (l <= h) {
    md = ((l + h) >> 1LLU);
    x = md + 1LLU;
    y = (md << 1LLU);
    x = dp(0, 0, 0, 0);
    cs++;
    if (x == n) {
      printf("%llu\n", md);
      return 0;
    }
    if (x <= n) {
      l = md + 1LLU;
    } else
      h = md - 1LLU;
  }
  printf("0\n");
  return 0;
}

```