Redemption


The MAPS team has been working hard to create problems for the MAPS Beginner Competition.

Currently, there are nn team members working on problem creation. In the final team meeting before the competition, which starts at time 1 and ends at time mm, each member ii is assigned a time interval [li,ri][l_i, r_i], during which they present their problems to Indra (a.k.a. the big boss). Here, lil_i and rir_i are natural numbers.

Unfortunately, Parsa has forgotten the exact time slot in which he was supposed to present his problems. However, he noticed an important rule in the meeting handbook: for every pair of team members, there must be at least one point during the meeting where both are presenting simultaneously.

Now, Parsa wonders how many possible time intervals [l,r][l, r] he could have had for his presentation while still satisfying this rule - meaning that for every other team member, there exists at least one time point tt within [l,r][l, r] where they are also presenting.

Note that:

  1. Intervals can be 0-length ([1,1][1, 1] is a valid interval).
  2. Two intervals overlap, even if their intersection is a singular point in time ([1,2][1, 2] and [2,3][2, 3] overlap).

Input

The first line of input contains nn and mm: the number of team members including Parsa and how long the meeting lasted.

The next n1n - 1 lines each contain two integers li,ril_i, r_i which are the intervals the iith person is presenting.

Output

Print the number of ways Parsa can choose an interval which holds the rule.

Constraints

  • 2n2000002 \le n \le 200000
  • 1m2000001 \le m \le 200000
  • 1lirim1 \le l_i \le r_i \le m

Example 1

Input 1
2 4
3 4
Output 1
7
Explanation

The other member presents on [3,4][3, 4]. There are 1010 intervals inside [1,4][1, 4], and the three that miss [3,4][3, 4] are [1,1][1, 1], [1,2][1, 2], and [2,2][2, 2]. The remaining 77 all overlap [3,4][3, 4].

Example 2

Input 2
2 2
1 1
Output 2
2
Explanation

Parsa must overlap [1,1][1, 1]. The valid choices are [1,1][1, 1] and [1,2][1, 2]. The interval [2,2][2, 2] does not overlap [1,1][1, 1].

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.