Tiles
문제
Soon after converting to Christianity, it is believed that the first and the only Lithuanian King Mindaugas ordered the construction of the Vilnius Cathedral. The construction is almost completed, except that the floor has to be covered with ceramic ornamented glazed tiles.
The floor of the Vilnius Cathedral is a polygon in a 2D plane with a Cartesian coordinate system. The polygon has distinct vertices, numbered from to . For each such that 1 ≤ i ≤ N, vertex is located at point , where and are nonnegative integers. There is an edge connecting vertex and vertex (for each such that 1 ≤ i ≤ N - 1), as well as an edge connecting vertex and vertex . The vertices are listed in either clockwise or counterclockwise order.
The cathedral is an axis-aligned polygon, which means that each of the edges is parallel to either the -axis or the -axis. Moreover, the cathedral is a simple polygon, that is:
- exactly two edges meet at each vertex;
- any pair of edges can only meet at a vertex.
The builders of the cathedral have infinitely many pieces of tiles. Each piece is a square with side length equal to . The builders would like to cover a big part of the cathedral with these pieces. Specifically, the builders want to pick some vertical line and cover the part of the cathedral to the left of the line. For any integer , let denote the vertical line consisting of points with -coordinate equal to . A covering of the part of the cathedral to the left of is a placement of some number of pieces in the plane such that:
- each point which lies in the interior of the polygon and has -coordinate less than is covered by some piece;
- no point which lies outside of the polygon or has -coordinate greater than is covered by some piece;
- the interiors of the pieces do not overlap.
The minimum -coordinate of any vertex in the cathedral is . Let denote the maximum -coordinate of any vertex in the cathedral.
Help the builders of the Vilnius Cathedral by determining the largest integer , such that k ≤ M, and there exists a covering of the part of the cathedral to the left of . Note that by definition, there exists a covering of the part of the cathedral to the left of (which uses pieces).
입력
The first line of the input contains two integers and – the number of vertices and the maximum -coordinate of any vertex.
Then, lines follow. The -th of them contains two integer numbers and – the coordinates of -th vertex. The vertices are listed in either clockwise or counterclockwise order.
출력
Your program should output the maximum , such that k ≤ M and there exists a covering of the part of the cathedral to the left of .
예제
예제 1
14 6 0 1 0 3 2 3 2 4 0 4 0 6 3 6 3 7 4 7 6 7 6 5 3 5 3 2 3 1
2
예제 2
4 3 0 0 0 3 3 3 3 0
0
예제 3
18 9 0 2 2 2 2 1 4 1 4 0 9 0 9 2 4 2 4 4 7 4 7 3 9 3 9 6 4 6 4 5 2 5 2 4 0 4
6