7399 - Buckets of Oats on the Wall   

Description

There are initially N buckets of oats on the wall, numbered from 1 to N and arranged in a circular shape. Now, starting from bucket number 1, every M bucket of oats will be eaten until there is only one bucket left. What is the number of that bucket?

 

Input

Each test case consists of two space-separated integers N and M (2 ≤ N ≤ 100, 1 ≤ M ≤ 10000), representing the variables defined in the problem statement.

The input is terminated by N = M = 0.

 

Output

2Output the number of the last bucket in a line for each test case

Sample Input  Download

Sample Output  Download

Tags




Discuss