CF101B.Buses

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n+1n+1 bus stops. All of them are numbered with integers from 00 to nn in the order in which they follow from Gerald's home. The bus stop by Gerald's home has number 00 and the bus stop by the school has number nn .

There are mm buses running between the house and the school: the ii -th bus goes from stop sis_{i} to tit_{i} ( s_{i}<t_{i} ), visiting all the intermediate stops in the order in which they follow on the segment. Besides, Gerald's no idiot and he wouldn't get off the bus until it is still possible to ride on it closer to the school (obviously, getting off would be completely pointless). In other words, Gerald can get on the ii -th bus on any stop numbered from sis_{i} to ti1t_{i}-1 inclusive, but he can get off the ii -th bus only on the bus stop tit_{i} .

Gerald can't walk between the bus stops and he also can't move in the direction from the school to the house.

Gerald wants to know how many ways he has to get from home to school. Tell him this number. Two ways are considered different if Gerald crosses some segment between the stops on different buses. As the number of ways can be too much, find the remainder of a division of this number by 10000000071000000007 ( 109+710^{9}+7 ).

输入格式

The first line contains two space-separated integers: nn and mm ( 1<=n<=109,0<=m<=1051<=n<=10^{9},0<=m<=10^{5} ). Then follow mm lines each containing two integers si,tis_{i},t_{i} . They are the numbers of starting stops and end stops of the buses ( 0<=s_{i}<t_{i}<=n ).

输出格式

Print the only number — the number of ways to get to the school modulo 10000000071000000007 ( 109+710^{9}+7 ).

输入输出样例

  • 输入#1

    2 2
    0 1
    1 2
    

    输出#1

    1
    
  • 输入#2

    3 2
    0 1
    1 2
    

    输出#2

    0
    
  • 输入#3

    5 5
    0 1
    0 2
    0 3
    0 4
    0 5
    

    输出#3

    16
    

说明/提示

The first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two.

In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 00 .

In the third test Gerald can either get or not on any of the first four buses to get closer to the school. Thus, the correct answer is 24=162^{4}=16 .

首页