#arc159d. [arc159_d]LIS 2

[arc159_d]LIS 2

Problem Statement

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

  • Append li,li+1,ldots,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

  • 1leqNleq2times1051 \\leq N \\leq 2 \\times 10^5
  • 1leqlileqrileq1091 \\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\\vdots lNl_{N} rNr_{N}

Output

Print the answer.


Sample Input 1

4
1 1
2 4
10 11
7 10

Sample Output 1

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.


Sample Input 2

4
1 1
1 1
1 1
1 1

Sample Output 2

1

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


Sample Input 3

1
1 1000000000

Sample Output 3

1000000000