Josephus Problem 3

No attempts yetTime limit1sMemory limit16 MB

Problem

The Josephus problem is as follows.

NN people numbered 1 to NN sit in a circle, and a positive integer KK (KNK \le N) is given. Counting in order, every KK-th person is removed. Once a person is removed, the counting continues around the circle formed by the remaining people. The process runs until all NN people are removed, and the order in which people are removed is the (N,K)(N, K)-Josephus permutation. For example, the (7,3)(7, 3)-Josephus permutation is <3, 6, 2, 7, 5, 1, 4>.

Given NN and KK, write a program that finds the number of the person who remains last.

Input

The first line contains NN and KK in that order, separated by a space. (1KN5,000,0001 \le K \le N \le 5{,}000{,}000)

Output

Print the number of the person who remains last on the first line.