League of Legends
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

ZLOIers love playing League of Legends, but they seldom have time to play together.

When summer vacation came, each of them scheduled some free time for it, which could be described as an interval (minute).

Now the ZLOIers plan to play in  groups. Each group will play together when all the players in it are free.Each ZLOIer joins exactly one group, and each group has at least one ZLOIer. The number of people in each group does not necessarily need to be equal.

Since they don't have a full plan of groups yet, they want you to maximize the total time the  groups can play.You should tell them maximum total time.

Note that a group must play at least minute, and the total time is not accumulated by each person, but by each group.

输入描述:

The first line contains two integers and .

In the following lines, the  line contains two integers a_i and b_i.

输出描述:

Output maximum total time. If there is no solution, output 0.
示例1

输入

复制
4 2
1 3
1 5
4 6
2 7

输出

复制
4
示例2

输入

复制
4 1
1 3
1 5
4 6
2 7

输出

复制
0

备注:

It is guaranteed that .