n players, labeled 1..n, stand in a circle in label order. A potato is passed according to this rule, applied repeatedly until only one player remains:
- Starting from the CURRENT holder, count
mplayers in the CURRENT direction (the holder themself counts as 1); them-th player counted is eliminated and removed from the circle. - Immediately after every elimination, the direction of counting REVERSES (clockwise becomes counter-clockwise and vice versa). The very first count, before any elimination has happened, proceeds CLOCKWISE - that is, in increasing label order starting from player 1, wrapping from the highest remaining label back to the lowest.
- After an elimination, the NEXT count of
mstarts from the player immediately next to the just-eliminated player, in the (new, reversed) direction.
Determine the label of the single surviving player.
Input format
A single line with two integers n and m.
Output format
A single integer: the label of the surviving player.
Constraints
- 1 <= n <= 2000
- 1 <= m <= 2000