#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const int iinf = 1 << 29;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long mrand(long long B) { return (unsigned long long)rng() % B; }
long long cross(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.first * p2.second - p2.first * p1.second;
}
bool online(pair<long long, long long> a, pair<long long, long long> b,
            pair<long long, long long> c) {
  pair<long long, long long> p1{b.first - a.first, b.second - a.second};
  pair<long long, long long> p2{c.first - a.first, c.second - a.second};
  return cross(p1, p2) == 0;
}
void z_func(vector<int> &z, vector<int> &s, int n) {
  int L = 0, R = 0;
  for (int i = 1; i < n; i++) {
    if (i > R) {
      L = R = i;
      while (R < n && s[R - L] == s[R]) R++;
      z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        L = i;
        while (R < n && s[R - L] == s[R]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
}
long long m;
int k;
long long CnK[65][65];
long long C(int n, int i) {
  if (i <= 0 || i > n || n <= 0) return 0;
  return CnK[n][i];
}
long long ok(long long n) {
  long long tot = 0;
  long long msb = 1LL << 62;
  int nbits_left = 62;
  while ((msb & n) == 0) {
    msb >>= 1;
    --nbits_left;
  }
  int ones_seen = 0;
  for (; msb; msb >>= 1, nbits_left--) {
    if ((msb & n) == 0) continue;
    tot += C(nbits_left, k - ones_seen);
    ++ones_seen;
    tot += ones_seen == k;
  }
  bitset<64> b(n);
  return tot;
}
const long long maxxx = 4e18 + 5;
void work() {
  cin >> m >> k;
  for (int i = 0; i < 65; ++i) CnK[i][0] = 1LL;
  for (int i = 1; i < 65; ++i) {
    for (int j = 1; j <= i; ++j) {
      CnK[i][j] = min(maxxx, CnK[i - 1][j - 1] + CnK[i - 1][j]);
    }
  }
  long long low = 1, high = 1e18;
  while (low <= high) {
    long long mid = low + ((high - low) >> 1);
    long long res = ok(mid << 1) - ok(mid);
    if (res == m) {
      cout << mid << endl;
      return;
    }
    if (res < m)
      low = mid + 1LL;
    else
      high = mid - 1LL;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  work();
  return 0;
}

### Prompt

Your challenge is to write 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 long long M = 1e9 + 7;
const int iinf = 1 << 29;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long mrand(long long B) { return (unsigned long long)rng() % B; }
long long cross(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.first * p2.second - p2.first * p1.second;
}
bool online(pair<long long, long long> a, pair<long long, long long> b,
            pair<long long, long long> c) {
  pair<long long, long long> p1{b.first - a.first, b.second - a.second};
  pair<long long, long long> p2{c.first - a.first, c.second - a.second};
  return cross(p1, p2) == 0;
}
void z_func(vector<int> &z, vector<int> &s, int n) {
  int L = 0, R = 0;
  for (int i = 1; i < n; i++) {
    if (i > R) {
      L = R = i;
      while (R < n && s[R - L] == s[R]) R++;
      z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        L = i;
        while (R < n && s[R - L] == s[R]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
}
long long m;
int k;
long long CnK[65][65];
long long C(int n, int i) {
  if (i <= 0 || i > n || n <= 0) return 0;
  return CnK[n][i];
}
long long ok(long long n) {
  long long tot = 0;
  long long msb = 1LL << 62;
  int nbits_left = 62;
  while ((msb & n) == 0) {
    msb >>= 1;
    --nbits_left;
  }
  int ones_seen = 0;
  for (; msb; msb >>= 1, nbits_left--) {
    if ((msb & n) == 0) continue;
    tot += C(nbits_left, k - ones_seen);
    ++ones_seen;
    tot += ones_seen == k;
  }
  bitset<64> b(n);
  return tot;
}
const long long maxxx = 4e18 + 5;
void work() {
  cin >> m >> k;
  for (int i = 0; i < 65; ++i) CnK[i][0] = 1LL;
  for (int i = 1; i < 65; ++i) {
    for (int j = 1; j <= i; ++j) {
      CnK[i][j] = min(maxxx, CnK[i - 1][j - 1] + CnK[i - 1][j]);
    }
  }
  long long low = 1, high = 1e18;
  while (low <= high) {
    long long mid = low + ((high - low) >> 1);
    long long res = ok(mid << 1) - ok(mid);
    if (res == m) {
      cout << mid << endl;
      return;
    }
    if (res < m)
      low = mid + 1LL;
    else
      high = mid - 1LL;
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  work();
  return 0;
}

```