Balls in a Binary Tree

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a full binary tree of height hh (see the figure).

Every edge is either open or closed. Initially all left edges are open. Starting from the root, you drop nn balls one by one. Each ball always travels through the currently open edge; immediately after passing through it, that edge is closed and the sibling edge of the same vertex is opened. In other words, if the left edge was open, the left one is closed and the right one is opened; if the right edge was open, the right one is closed and the left one is opened.

Determine which leaf vertex the nn-th ball reaches. The bottom vertices are numbered from 00 to 2h12^h - 1, left to right.

Input

The first line contains two integers nn and hh (1n1081 \le n \le 10^8, 0h300 \le h \le 30): the number of balls dropped and the height of the binary tree, respectively.

Output

Print a single integer: the number of the vertex the nn-th ball reaches.

Hint

For a tree of height 22, the balls land in vertices numbered 0,2,1,30, 2, 1, 3 in order, so the 4th ball reaches vertex 33. When h=0h = 0 the tree has a single vertex (numbered 00), so every ball lands in vertex 00.