The Josephus problem is notoriously known. For those who are not familiar with the problem, among n people numbered 1, 2, . . . , n, standing in circle every mth is going to be executed and only the life of the last remaining person will be saved. Joseph was smart enough to choose the position of the last remaining person, thus saving his life to give the message about the incident.
Given a group of n men arranged in a circle under the edict that every m man will be executed going around the circle until only one remains. Find the position in which you should stand in order to be the last survivor.
Each line with 2 integers, n, m. n is the number of people. m is the number that every m person is executed. Input terminated by EOF.
The output will consist in separate lines containing the position of the person which life will be saved. Each line should be ended with a newline character '\n'.