PivotOJ

Tiles

시간 제한: 2000ms메모리 제한: 1024MB출처: BOI 2024BOJ 31972

문제

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 NN distinct vertices, numbered from 11 to NN. For each ii such that 1 ≤ i ≤ N, vertex ii is located at point (X[i],Y[i])(X[i],Y[i]), where X[i]X[i] and Y[i]Y[i] are nonnegative integers. There is an edge connecting vertex ii and vertex i+1i + 1 (for each ii such that 1 ≤ i ≤ N - 1), as well as an edge connecting vertex NN and vertex 11. 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 xx-axis or the yy-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 22. 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 kk, let LkL_k denote the vertical line consisting of points with xx-coordinate equal to kk. A covering of the part of the cathedral to the left of LkL_k 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 xx-coordinate less than kk is covered by some piece;
  • no point which lies outside of the polygon or has xx-coordinate greater than kk is covered by some piece;
  • the interiors of the pieces do not overlap.

The minimum xx-coordinate of any vertex in the cathedral is 00. Let MM denote the maximum xx-coordinate of any vertex in the cathedral.

Help the builders of the Vilnius Cathedral by determining the largest integer kk, such that k ≤ M, and there exists a covering of the part of the cathedral to the left of LkL_k. Note that by definition, there exists a covering of the part of the cathedral to the left of L0L_0 (which uses 00 pieces).

입력

The first line of the input contains two integers NN and MM – the number of vertices and the maximum xx-coordinate of any vertex.

Then, NN lines follow. The ii-th of them contains two integer numbers xix_i and yiy_i – the coordinates of ii-th vertex. The vertices are listed in either clockwise or counterclockwise order.

출력

Your program should output the maximum kk, such that k ≤ M and there exists a covering of the part of the cathedral to the left of LkL_k.

예제

예제 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
코드를 제출하려면 로그인하세요.