Joseph Problem#5023

Joseph Problem

1 second
128 megabytes
Very easy

boys are standing in a circle. They start counting themselves clockwise, starting from . As soon as the count reaches , the last boy counted leaves the circle, and they continue counting from the next boy, starting from again.

The last remaining boy wins.

Boys are numbered from to in clockwise order, starting from the boy from whom the counting originally started.

Can you determine the number of the last remaining boy in the circle?

Input

The input contains two integers and (1 \le n, p \le 10^6).

Output

Print one number — the original number of the last boy.

Examples

Example 1

Loading
Loading