#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<pair<int, int>, pair<int, int> >& p1,
         const pair<pair<int, int>, pair<int, int> >& p2) {
  if (p1.first.first / 317 != p2.first.first / 317)
    return p1.first.first / 317 < p2.first.first / 317;
  return p1.first.second < p2.first.second;
}
int l;
int k;
long long int mem[70][70];
vector<int> sol_array(long long int x) {
  vector<int> ans;
  while (x > 0) {
    long long int p = x % 2;
    ans.push_back(p);
    x = x / 2;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
long long int sol1(int idx, int cn) {
  if (idx == l) {
    if (cn == k) return 1;
    return 0;
  }
  if (mem[idx][cn] != -1) return mem[idx][cn];
  long long int ans = 0;
  for (int i = 0; i <= 1; i++) ans += (sol1(idx + 1, cn + i));
  mem[idx][cn] = ans;
  return ans;
}
long long int sol(long long int x) {
  vector<int> v;
  v = sol_array(x);
  int sum = 0;
  l = v.size();
  memset(mem, -1, sizeof(mem));
  long long int ans = 0;
  for (int i = 0; i < l; i++) {
    int curr = v[i];
    for (int j = 0; j < curr; j++) {
      ans = ans + sol1(i + 1, sum + j);
    }
    sum += curr;
  }
  if (sum == k) ans++;
  return ans;
}
int main() {
  long long int m;
  scanf("%I64d", &m);
  scanf("%I64d", &k);
  long long int low = 1, high = 1000000000000000000ll;
  long long int res = 0;
  while (low <= high) {
    long long int mid = (low + high) / 2;
    long long int r = sol(mid * 2ll);
    long long int l = sol(mid);
    long long int ans = r - l;
    if (ans >= m) {
      if (ans == m) res = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  printf("%I64d\n", res);
  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;
bool cmp(const pair<pair<int, int>, pair<int, int> >& p1,
         const pair<pair<int, int>, pair<int, int> >& p2) {
  if (p1.first.first / 317 != p2.first.first / 317)
    return p1.first.first / 317 < p2.first.first / 317;
  return p1.first.second < p2.first.second;
}
int l;
int k;
long long int mem[70][70];
vector<int> sol_array(long long int x) {
  vector<int> ans;
  while (x > 0) {
    long long int p = x % 2;
    ans.push_back(p);
    x = x / 2;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
long long int sol1(int idx, int cn) {
  if (idx == l) {
    if (cn == k) return 1;
    return 0;
  }
  if (mem[idx][cn] != -1) return mem[idx][cn];
  long long int ans = 0;
  for (int i = 0; i <= 1; i++) ans += (sol1(idx + 1, cn + i));
  mem[idx][cn] = ans;
  return ans;
}
long long int sol(long long int x) {
  vector<int> v;
  v = sol_array(x);
  int sum = 0;
  l = v.size();
  memset(mem, -1, sizeof(mem));
  long long int ans = 0;
  for (int i = 0; i < l; i++) {
    int curr = v[i];
    for (int j = 0; j < curr; j++) {
      ans = ans + sol1(i + 1, sum + j);
    }
    sum += curr;
  }
  if (sum == k) ans++;
  return ans;
}
int main() {
  long long int m;
  scanf("%I64d", &m);
  scanf("%I64d", &k);
  long long int low = 1, high = 1000000000000000000ll;
  long long int res = 0;
  while (low <= high) {
    long long int mid = (low + high) / 2;
    long long int r = sol(mid * 2ll);
    long long int l = sol(mid);
    long long int ans = r - l;
    if (ans >= m) {
      if (ans == m) res = mid;
      high = mid - 1;
    } else
      low = mid + 1;
  }
  printf("%I64d\n", res);
  return 0;
}

```