The task of Josephus
There is a legend that Flavius Josephus, a famous historian of the first century, survived and became famous thanks to his mathematical talent.
During the Jewish war, he, as part of a detachment of 41 Jewish soldiers, was driven by the Romans into a cave. Preferring suicide to captivity, the warriors decided
line up in a circle and sequentially kill every third of living people until there is not a single person left.
However, Joseph, along with one of his associates, found such a end pointless - he quickly figured out the saving places
in a vicious circle, on which he put himself and his comrade. And that's the only reason we know his story.
In our version, we'll start by arranging N people in a circle, numbered from 1 to N, and excluding every k-th person until only
one person. (For example, if N=10, k=3, then the 3rd will die first, then the 6th, then the 9th, then the 2nd, then the 7th, then the 1st, then the 8th , behind it - the 5th, and then the 10th. Thus, the 4th will survive.)
Task: determine the number of the survivor.
Input: The numbers N and k are entered from a string.
Limits: 1<=N<=500, 1<=k<=100.
Output: The program should output the number of the survivor.
Example input file:
10 3
Example output file:
4