Under construction

Still being built. Things may change

Planine

Time limit2sMemory limit512 MB

Summary
Given a mountain profile of alternating peaks and valleys at height below h, find the minimum number of fairies at height h needed so every valley is visible from some fairy.
Level

Medium7 of 10

Topics
Greedy, Geometry, Implementation
Solved
No attempts yet

Problem

Zoran wanders across his Dalmatian homeland to forget his love woes. He comes across a mountain of a specific shape, behind which a young maiden is waiting for him. The mountain is described by nn alternating low and high points, where nn is odd. Points at odd indices, except the first and the last point, are called valleys.

Zoran is afraid of the dark. Even the call of love will not give him courage to cross the mountain at night. As usual, the fairies of Velebit come to the rescue.

We model each fairy by a luminous dot at a fixed height hh. A fairy illuminates a valley if and only if the segment connecting the fairy and the valley does not intersect the interior of the mountain.

The mountain from the first example, and a fairy illuminating all three valleys.

What is the least number of fairies that can illuminate all the valleys simultaneously?

Input

The first line contains two integers nn (3≤n<1063 \le n < 10^6, nn odd) and hh (1≤h≤1061 \le h \le 10^6), the number of points describing the mountain and the height the fairies live at.

The ii-th of the following nn lines contains integers xix_i and yiy_i (−106≤xi≤106-10^6 \le x_i \le 10^6, 0≤yi<h0 \le y_i < h), the coordinates of the ii-th point of the mountain.

It is guaranteed that x1<x2<⋯<xnx_1 < x_2 < \cdots < x_n, and y1<y2y_1 < y_2, y2>y3y_2 > y_3, y3<y4y_3 < y_4, …\ldots, yn−1>yny_{n-1} > y_n.

Output

Print the least number of fairies such that all valleys are illuminated.

Hint

The first example is shown in the statement. It can be shown that the valleys in the second example cannot be illuminated using only one fairy. An example with two fairies is given in the figure below.

Examples2

  1. Example 1

    Input
    9 6
    0 0
    1 2
    3 0
    6 3
    8 1
    9 2
    11 1
    12 4
    14 0
    
    Expected output
    1
    
  2. Example 2

    Input
    9 5
    -5 2
    -4 3
    -2 1
    0 4
    2 2
    3 3
    4 1
    5 2
    6 1
    
    Expected output
    2