Time Limit: 1000 ms
Memory Limit: 65535 ms
The Josephus problem is the following game: N people, numbered 1 to N, are sitting in a circle. Starting at person 1, a hot potato is passed. After M passes, the person holding the hot potato is eliminated, and the game continues with the person who was sitting after the eliminated person picking up the hot potato. The last remaining person wins.
Now, given N and the last remaining person's id, what is M?
Every line has two integers: n(2 <= n <= 200) and id(1 <= id <= n). Input is terminated by EOF.
For each input line, output one line containing M. If there are more than one M satisfying the request, output the smallest.
The First ACM-ICPC Nanjing Invitational Tourn