Олимпиадный тренинг

Задача 38494. Rhythm


Задача

Темы:
To choose a driver in a children's game, N people stand in a circle, after which a counting rhyme is pronounced. On the first word of the rhyme, the first person in the circle is indicated, & nbsp; on the second word & ndash; on the second person, etc. After the N-th person, the first person comes again (all people in the circle are numbered from 1 to N, the circle loops, after the person with number N comes the person with number 1).
There are M words in the counting rhyme. Decide which person will have the last word calculus.
The program receives two positive integers as input. The first number is N – the number of people in the circle. Second number M – the number of words in the counter. Both numbers are not greater than 109.
The program should output a single integer from 1 to N – the number of the person in the circle who will have the last word of the rhyme.
Examples
# Input Output
1 10
25
5