atcoder#ARC159D. [ARC159D] LIS 2

[ARC159D] LIS 2

Score : 600600 points

Problem Statement

We have a sequence XX, which is initially empty. Takahashi has performed the following operation for i=1,2,,Ni=1,2,\ldots,N in this order.

  • Append li,li+1,,ril_i,l_i+1,\ldots,r_i in this order to the end of XX.

Find the greatest length of a strictly increasing subsequence of the final XX.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1liri1091 \leq l_i \leq r_i \leq 10^9
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

l1l_1 r1r_1

\vdots

lNl_{N} rNr_{N}

Output

Print the answer.

4
1 1
2 4
10 11
7 10
8

The final XX is (1,2,3,4,10,11,7,8,9,10)(1,2,3,4,10,11,7,8,9,10). The 11-st, 22-nd, 33-rd, 44-th, 77-th, 88-th, 99-th, and 1010-th elements form a strictly increasing subsequence with the greatest length.

4
1 1
1 1
1 1
1 1
1

The final XX is (1,1,1,1)(1,1,1,1).

1
1 1000000000
1000000000