eolymp
Competitions

Five for week 20 (2013-2014)

Joseph Problem

Time limit 1 second
Memory limit 128 MiB

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

Last remaining boy wins.

Can you calculate his number in clockwise order, if the boy from whom the counting originally started has number 1?

Input data

Two integers n and p (1n, p10^6).

Output data

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

Examples

Input example #1
3 4
Output example #1
2
Author Andrew Lopatin, Nick Durov
Source Petrozavodsk Summer 2003. Blitz Kontest, Monday, August 25