Sakurako and Her Trip#407

Sakurako and Her Trip

1 second
256 megabytes
Hard

This summer, Sakurako decided to visit a new country. After arriving, her tour guide warned her about tourist traps that would make her spend some money. The city that Sakurako is in can be represented as an n\times n square grid.

Currently, she is in position . Her task is to arrive at the airport that is positioned in square . During her travel, she wants to be as far as possible from all tourist traps.

Each tourist trap has its position (x_i, y_i). The distance from current Sakurako's position (x_S, y_S) to tourist trap is calculated as D(i, x_S, y_S)=|x_i-x_S|+|y_i-y_S|.

During her trip through the grid, she may move to any adjacent cell ((x, y)\to (x+1,y);(x-1,y);(x,y-1);(x,y+1) with the constraint that the new position is a valid cell in a grid (1\le x_{new},y_{new}\le n)).

Let set denote all cells in a grid that Sakurako visits during her trip.

Your task is to maximize \displaystyle\min\limits_{\underset{(x,y)\in S}{i\in[1,m]}}D(i,x,y).

In other words, you need to choose Sakurako's trip in a way that maximizes the minimal distance to all tourist traps during her travel. You need to output the maximal possible minimal distance.

Input

The first line contains two integers (2\le n \le 10^9; 1\le m\le 5\,000) — the size of the grid and the amount of tourist traps in the city.

Each of the next lines contains two integers: x_i,y_i (1\le x_i, y_i\le n; (x_i,y_i)\neq(1,1); (x_i,y_i)\neq(n,n)), which correspond to the position of tourist trap .

Output

You should output a single integer — the answer to the task.

Examples

Example 1

Loading
Loading

Note

One of the optimal paths for the first example.

Scoring

  • ( points): n,m\le 100;

  • ( points): n,m\le 10^3;

  • ( points): n \le 10^3;

  • ( points): either x_1=x_2=\dots=x_m or y_1=y_2=\dots=y_m;

  • ( points): without additional constraints.