Bobi has toys that can be colored in various colors. For each color, the interval is known, meaning that any toy in the interval can be colored in color . A subset of toys is considered compatible if there exists at least one common color in which they can all be colored.
Task
Count how many compatible subsets of toys exist, modulo .
Input data
The first line contains the numbers and , representing the number of toys and the number of colors, respectively.
The next lines contain two integers and , representing the interval of toys that can be colored in color .
Output data
Print a single number representing the number of compatible subsets of toys, modulo .
Constraints and clarifications
- For test cases worth points,
- For other test cases worth points,
Example 1
stdin
5 3
1 4
2 3
4 5
stdout
18
Explanation
The compatible subsets are: , , , , , , , , , , , , , , , , , and . For example, the subset would not be compatible because toys and do not have a common color.
Example 2
stdin
5 1
1 5
stdout
32
Explanation
All subsets are compatible.