Josephus problem#971

Josephus problem

1 second
64 megabytes
Medium

In a circle, there are objects labeled from to . Starting from the first object, every -th object is eliminated from the circle in turn, and this process continues until only one object remains.

For example, if N = 10 and k = 3, the order of elimination will be: , , , , , , , , . The object labeled will be the last one remaining.

Input

The input contains two positive integers and . 1 \leq N \leq 500, 1 \leq k \leq 100.

Output

The output should contain a single number—the label of the remaining object.

Examples

Example 1

Loading
Loading