A. New Functionality
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently, a new feature has been added to the main Kyrgyz website for programming competitions — the division of problems into separate volumes.

Volumes are numbered with integers starting from 1. Inside each volume, problems are numbered with integers from 0 to n.

Thus, each problem corresponds to a pair of numbers (v, k) — the volume number and the number within the volume, respectively.

Additionally, within each problem, there is a button labeled "go to next":

  • If k < n, the button opens problem (v, k + 1).
  • Otherwise, the button opens problem (v + 1, 0).

At the moment, you are on the page of problem (a, b). You are interested in how many button presses are required to reach problem (c, d)?

Input

The first line contains an integer n (1 ≤ n ≤ 1000) — the maximum possible problem number within a volume.

The second line contains two integers a and b (1 ≤ a ≤ 1000, 0 ≤ b ≤ n) — the number of the problem you are currently on.

The third line contains two integers c and d (1 ≤ c ≤ 1000, 0 ≤ d ≤ n) — the number of the problem you want to reach.

It is guaranteed that it is possible to reach problem (c, d) from problem (a, b):

  • either a < c;
  • or a = c and b < d.
Output

In a single line, output an integer — the required number of presses of the "go to next" button after which you will reach problem (c, d) from problem (a, b).

Examples
Input
12
2 5
2 8
Output
3
Input
8
3 4
4 5
Output
10
Input
14
2 11
4 1
Output
20
Note

First test case

The sequence of presses (2, 5) — (2, 6) — (2, 7) — (2, 8) — a total of 3 presses.

Second test case

The sequence of presses:

  • (3, 4) — (3, 8) — a total of 4 presses;
  • (3, 8) — (4, 0) — 1 press;
  • (4, 0) — (4, 5) — another 5 presses.

A total of 10 presses.