Problems
Bit sorting
Bit sorting
On the set of nonnegative integers, we introduce the following order relation: we assume that the number of A is less than the number of B in two cases:
- When a binary number in units of A is less than B.
- When a binary number with A as many units as in B, and A less than B in the usual sense.
Now sort ascending set of all integers from 0 to n inclusive, using this new order relation. Your task is to find how many will be in position k. Numbering of positions is carried out with the unit.
Input
The first line contains the integers n and k (0 ≤ n ≤ 1016
, 1 ≤ k ≤ n + 1).
Output
Print the k-th number in the sorted sequence.
Explanation
Numbers from 0 to 10 will be sorted in the next way: 0, 1, 2, 4, 8, 3, 5, 6, 9, 10, 7.
Input example #1
10 7
Output example #1
5