시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 1 1 1 100.000%

문제

Master Zhu has a rectangular board consisting of $N$ rows and $M$ columns. In the $i$-th row, the squares from the column $L_i$ to the column $R_i$ inclusive are colored black, and all other squares are colored white. Additionally, it is known that $L_i \le L_{i + 1}$ and $R_i \le R_{i + 1}$. Now Master Zhu is going to place some chess pieces on several black squares so that for each black square, there is at least one chess piece in its row or in its column.

Find the minimum number of chess pieces he should place.

입력

The first line of the input contains two integers $N$ and $M$: the number of rows and columns $(1 \le N, M \le 100)$. Each of the next $N$ lines contains two integers $L_i$ and $R_i$ ($1 \le L_i \le R_i \le M$). It is guaranteed that $L_i \le L_{i + 1}$ and $R_i \le R_{i + 1}$.

출력

Output the minimum number of chess pieces Master Zhu should place.

예제 입력 1

3 3
1 1
2 2
3 3

예제 출력 1

3

예제 입력 2

2 4
1 3
2 4

예제 출력 2

2

예제 입력 3

3 2
1 2
1 2
1 2

예제 출력 3

2