#t251. 天使的起誓(yubikili)

天使的起誓(yubikili)

The Angel's Oath

Problem Background

TENSHI was very lucky to be chosen as the angel in charge of the Key of Wisdom. Before officially taking office, she, like the other newly elected angels, must take an oath. In the ceremony, each angel states her own mission; their speeches are placed in nn treasure boxes arranged in a circle. These boxes are numbered clockwise 1,2,3,…,n−1,n1, 2, 3, \ldots, n-1, n.

At the beginning the angels stand next to the box numbered nn. Each holds a number representing, counting clockwise from box 11, which box her speech is in. For example, with 77 boxes, if TENSHI's number is 99, then her speech is in the 22nd box. Now the angels start looking for their speeches according to their numbers; whoever finds hers first may speak first. TENSHI found hers at once and was the first to step up: "I will lead everyone to open the door of NOI…" After TENSHI's oath, other angels came up one after another. But one angel searched for a long time without finding her speech — her number mm was so large that she went around many times and still could not find the box she wanted.

Problem Description

Please help this angel find the number of the box she is looking for.

Input Format

The first and second lines each contain a positive integer nn and mm, where nn and mm satisfy 2≤n≤1082 \le n \le 10^8 and 2≤m≤101002 \le m \le 10^{100}.

Output Format

The number of the box she is looking for.

Sample Input

Sample Input 1

7
9

Sample Input 2

11
108

Sample Output

Sample Output 1

2

Sample Output 2

9

Constraints

1s, 1024KiB for each test case.