eolymp
bolt
Try our new interface for solving problems
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:

  1. When a binary number in units of A is less than B.
  2. 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 (0n1016, 1kn + 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.

Time limit 1 second
Memory limit 128 MiB
Input example #1
10 7
Output example #1
5