# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Limits
1s, 512 MB

In a country there are **N** cities numbered from **1** to **N**. To Travel along the cities there are total **N** bi directional roads. For each city numbered **i** (**1 ≤ i < N**) there is a bi-directional road between city **i** and city **i+1**. Furthermore, there is a road between city **N** and city **1**. People can only use any of these roads to travel from a city to another. As travel technology of this country is very advanced, it requires only **1** second time to travel from city **i** to city **j** if there is a road between these two cities. Now initially you will be given the address of **M** people. That is, for every people **i** you will be given an integer **a _{i}**, the city where

On the first line, there will be **two** integers **N** and **M** described in statement. Then the next **M** line will contain **one** number each, **i ^{th}** of them will be

**Constraints:**

For each query print an integer, the total time that is required for all **M** people to travel from their city to city **X**.

Input | Output |
---|---|

10 2 2 9 2 10 5 | 3 7 |