#ABC230D. [ABC230D] Destroyer Takahashi

[ABC230D] Destroyer Takahashi

Score : 400400 points

Problem Statement

In a town divided into a grid with NN rows and 10910^9 columns, there are NN walls, numbered 11 to NN. Wall ii ranges from the LiL_i-th column to the RiR_i-th column from the left in the ii-th row from the top. (See also the figure at Sample Input and Output 11.)

Takahashi has decided to destroy all NN walls. With his superhuman strength, his one punch can damage consecutive DD columns at once.

  • More formally, he can choose an integer xx between 11 and 109D+110^9 - D + 1 (inclusive) to damage all walls that exist (or partly exist) in the xx-th through (x+D1)(x + D - 1)-th columns and are not yet destroyed.

When a part of a wall is damaged, that whole wall will be destroyed by the impact of the punch. (See also the figure at Sample Input and Output 11.)

At least how many times does Takahashi need to punch to destroy all walls?

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1D1091 \leq D \leq 10^9
  • 1LiRi1091 \leq L_i \leq R_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN DD

L1L_1 R1R_1

L2L_2 R2R_2

\vdots

LNL_N RNR_N

Output

Print the minimum number of punches needed to destroy all walls.

3 3
1 2
4 7
5 9
2

The figure below describes the arrangements of walls in Sample Input 11.

image

He can destroy all walls with two punches, such as the following. (Below, [a,b]\lbrack a, b \rbrack denotes the range from the aa-th through bb-th columns.)

  • First, punch [2,4]\lbrack 2, 4 \rbrack. The walls existing in [2,4]\lbrack 2, 4 \rbrack ― Walls 11 and 22 ― are damaged and destroyed.
  • Second, punch [5,7]\lbrack 5, 7 \rbrack. The wall existing in [5,7]\lbrack 5, 7 \rbrack ― Wall 33 ― is damaged and destroyed.

It is also possible to destroy all walls with two punches in this way:

  • First, punch [7,9]\lbrack 7, 9 \rbrack to destroy Walls 22 and 33.
  • Second, punch [1,3]\lbrack 1, 3 \rbrack to destroy Wall 11.
3 3
1 2
4 7
4 9
1

The difference from Sample Input/Output 11 is that Wall 33 now covers [4,9]\lbrack 4, 9 \rbrack, not [5,9]\lbrack 5, 9 \rbrack. In this case, he can punch [2,4]\lbrack 2, 4 \rbrack to destroy all walls with one punch.

5 2
1 100
1 1000000000
101 1000
9982 44353
1000000000 1000000000
3