Under construction

Still being built. Things may change

Indicator

Interview

Time limit2sMemory limit1024 MB

Summary
Given a cyclic counter from 1 to m, find the fewest button presses that move it from a to b.
Level

Easy1 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Losyash decided to take up running and borrowed a stopwatch from Pin. A few weeks later he was fitter and started running more than one lap at a time at the stadium. That is when he ran into a classic athletics problem: if you run long enough, you lose track of how many laps you have finished and how many are left. Luckily the stopwatch had an indicator that shows the current lap number. Each time he crossed the finish line, he pressed a button on the stopwatch and the number on the indicator went up by one.

What kind of indicator can show arbitrarily large natural numbers? None. The indicator is built around a gear with mm teeth. The teeth have the natural numbers from 1 to mm written on them, and the gear turns each time the button is pressed. So if the indicator shows mm and the button is pressed, the display resets to 1.

After one run, Losyash remembered that Sovunya had asked to borrow the stopwatch so she could cook Sichuan sauce exactly by the recipe. Losyash loves that sauce, so he went to Sovunya's place right away. He also wanted to make her happy by setting the indicator to bb, her favorite number. Since bb is between 1 and mm, the indicator can show it. At that moment the indicator showed aa.

Losyash did not want to do anything extra, so he decided to press the button as few times as possible to make the indicator show bb. He was too lazy to count the presses he had made, so that count is up to you.

Input

The first line contains the integer mm, the largest value the indicator can show (2≤m≤1002 \le m \le 100).

The second line contains the integer aa, the value the indicator initially showed (1≤a≤m1 \le a \le m).

The third line contains the integer bb, Sovunya's favorite number (1≤b≤m1 \le b \le m).

Output

Print one integer: the minimum number of button presses needed for the indicator to show bb.

Hint

In the first example the stopwatch already shows Sovunya's favorite number, so nothing needs to be done.

In the second example three presses are needed: 2→3→4→52 \to 3 \to 4 \to 5.

In the third example four presses are needed: 8→9→1→2→38 \to 9 \to 1 \to 2 \to 3.

Examples3

  1. Example 1

    Input
    30
    30
    30
    
    Expected output
    0
    
  2. Example 2

    Input
    10
    2
    5
    
    Expected output
    3
    
  3. Example 3

    Input
    9
    8
    3
    
    Expected output
    4