#include <bits/stdc++.h>
using namespace std;
inline int log(const char *format, ...) { return 0; }
const double EPS = 10e-8;
const int MAX = 1000;
const int INF = 1 << 30;
unsigned long long A, B;
long long dp[65][65][2][2];
long long check(int n, int k, bool gtA, bool ltB) {
  if (n == 0) {
    if (k == 0) {
      return 1;
    } else {
      return 0;
    }
  }
  if (k < 0) return 0;
  long long &ans = dp[n][k][gtA][ltB];
  if (ans != -1) return ans;
  ans = 0;
  int pos = n - 1;
  int bitA = (A & (1ll << pos)) != 0;
  int minBit = gtA ? 0 : bitA;
  int bitB = (B & (1ll << pos)) != 0;
  int maxBit = ltB ? 1 : bitB;
  for (int i = maxBit; i >= minBit; i--) {
    bool ga = gtA | (i > bitA);
    bool lb = ltB | (i < bitB);
    ans += check(n - 1, k - i, ga, lb);
  }
  return ans;
}
int main(int argc, char **argv) {
  long long m, k;
  cin >> m >> k;
  long long low = 1ll, high = 1000000000000000005ll;
  long long ans = -1;
  while (low < high) {
    long long mid = (low + high) / 2;
    A = mid + 1;
    memset(dp, -1, sizeof dp);
    B = mid * 2;
    int pos = 62;
    while ((B & (1ll << pos)) == 0) pos--;
    long long ch = check(pos + 1, k, false, false);
    if (ch == m) {
      ans = mid;
      break;
    } else if (ch > m) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  cout << ans;
  return EXIT_SUCCESS;
}

### Prompt

Please formulate 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;
inline int log(const char *format, ...) { return 0; }
const double EPS = 10e-8;
const int MAX = 1000;
const int INF = 1 << 30;
unsigned long long A, B;
long long dp[65][65][2][2];
long long check(int n, int k, bool gtA, bool ltB) {
  if (n == 0) {
    if (k == 0) {
      return 1;
    } else {
      return 0;
    }
  }
  if (k < 0) return 0;
  long long &ans = dp[n][k][gtA][ltB];
  if (ans != -1) return ans;
  ans = 0;
  int pos = n - 1;
  int bitA = (A & (1ll << pos)) != 0;
  int minBit = gtA ? 0 : bitA;
  int bitB = (B & (1ll << pos)) != 0;
  int maxBit = ltB ? 1 : bitB;
  for (int i = maxBit; i >= minBit; i--) {
    bool ga = gtA | (i > bitA);
    bool lb = ltB | (i < bitB);
    ans += check(n - 1, k - i, ga, lb);
  }
  return ans;
}
int main(int argc, char **argv) {
  long long m, k;
  cin >> m >> k;
  long long low = 1ll, high = 1000000000000000005ll;
  long long ans = -1;
  while (low < high) {
    long long mid = (low + high) / 2;
    A = mid + 1;
    memset(dp, -1, sizeof dp);
    B = mid * 2;
    int pos = 62;
    while ((B & (1ll << pos)) == 0) pos--;
    long long ch = check(pos + 1, k, false, false);
    if (ch == m) {
      ans = mid;
      break;
    } else if (ch > m) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  cout << ans;
  return EXIT_SUCCESS;
}

```