#include <map>
#include <set>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <ctime>
#include <cfloat>
#include <vector>
#include <string>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3FFFFFFFFFLL

#define FILL(X, V) memset( X, V, sizeof(X) )
#define TI(X) __typeof((X).begin())
#define ALL(V) V.begin(), V.end()
#define SIZE(V) int((V).size())

#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define RFOR(i, b, a) for(int i = b; i >= a; --i)
#define REP(i, N) for(int i = 0; i < N; ++i)
#define RREP(i, N) for(int i = N-1; i >= 0; --i)
#define FORIT(i, a) for( TI(a) i = a.begin(); i != a.end(); i++ )

#define PB push_back
#define MP make_pair

template<typename T> T inline SQR( const T &a ){ return a*a; }
template<typename T> T inline ABS( const T &a ){ return a < 0 ? -a : a; }
template<typename T> T inline MIN( const T& a, const T& b){ if( a < b ) return a; return b; }
template<typename T> T inline MAX( const T& a, const T& b){ if( a > b ) return a; return b; }

const double EPS = 1e-9;
inline int SGN( double a ){ return a > EPS ? 1 : (a < -EPS ? -1 : 0); }
inline int CMP( double a, double b ){ return SGN(a - b); }

typedef long long int64;
typedef unsigned long long uint64;

using namespace std;

#define MAXM 100100

int N, M;

struct bus_t{
	int s, t;
	bus_t( int ss = 0, int tt = 0 ) : s(ss), t(tt) {}
	bool operator < ( const bus_t& b ) const {
		if( t != b.t ) return b < b.t;
		return s < b.s;
	}
};

bus_t bus[MAXM];

const int64 MOD = 1000000007LL;

int bit[2*MAXM + 1];
void up( int x, int tt ){
	while( x <= (2*MAXM) ){
		bit[x] = bit[x] + tt;
		bit[x] %= MOD;
		x += ( x & -x );
	}
}

int get( int x ){
	int ans = 0;
	while( x > 0 ){
		ans += bit[x];
		ans %= MOD;
		x -= ( x & -x );
	}
	return ans;
}

int main( int argc, char* argv[] ){

	ios::sync_with_stdio( false );

	cin >> N >> M;

	map< int, int > occ;
	REP( i, M ){
		cin >> bus[i].s >> bus[i].t;
		occ[ bus[i].s ]++;
		occ[ bus[i].t ]++;
	}
	occ[ 0 ]++;

	sort( bus, bus+M );
	occ[ N ]++;

	map< int, int > id;
	int cid = 1;
	FORIT( x, occ ) id[ x->first ] = cid++;

	up( 1, 1 );
	REP( i, M ){
		up( id[ bus[i].t ], ( get( id[ bus[i].t ]-1 ) - get( id[ bus[i].s ]-1 ) + MOD ) % MOD );
	}

	cout << ( get( id[N] ) - get( id[N] - 1 ) + MOD ) % MOD << "\n";

	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 100;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
ll dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	sort(v.begin(), v.end());
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			ll cur = sum[v[idx].first - 1];
			if(v[idx].second) cur -= sum[v[idx].second - 1];
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] += sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
int dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	clr(dp, 0);
	clr(sum, 0);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sort(v.begin(), v.end());
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			int cur = sum[v[idx].first - 1];
			if(v[idx].second) cur -= sum[v[idx].second - 1];
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] = sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
int dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	sort(v.begin(), v.end());
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			int cur = sum[v[idx].first - 1];
			if(v[idx].second > 0) cur -= sum[v[idx].second - 1];
			cur %= REM;
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] += sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
int dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	clr(dp, 0);
	clr(sum, 0);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sort(v.begin(), v.end());
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			int cur = sum[v[idx].first - 1];
			if(v[idx].second) cur -= sum[v[idx].second - 1];
			if(cur < 0){
				cout << v[idx].first << " " << v[idx].second << endl;
				cout << sum[v[idx].first - 1] << endl;
				if(v[idx].second) cout << sum[v[idx].second - 1] << endl;
				return 0;
			}
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] = sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
int dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	clr(dp, 0);
	clr(sum, 0);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sort(v.begin(), v.end());
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			int cur = sum[v[idx].first - 1];
			if(v[idx].second) cur -= sum[v[idx].second - 1];
			if(cur < 0){
				cout << sum[v[idx].first - 1] << endl;
				if(v[idx].second) cout << sum[v[idx].second - 1] << endl;
				return 0;
			}
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] = sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
int dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	sort(v.begin(), v.end());
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			int cur = sum[v[idx].first - 1];
			if(v[idx].second) cur -= sum[v[idx].second - 1];
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] += sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
int dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sort(v.begin(), v.end());
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			int cur = sum[v[idx].first - 1];
			if(v[idx].second) cur -= sum[v[idx].second - 1];
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] = sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
int dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	sort(v.begin(), v.end());
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			int cur = sum[v[idx].first - 1];
			if(v[idx].second) cur -= sum[v[idx].second - 1];
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] = sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	if(dp[c - 1] < 0) cout << c << endl;
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
int dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	clr(dp, 0);
	clr(sum, 0);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sort(v.begin(), v.end());
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			int cur = sum[v[idx].first - 1];
			if(v[idx].second) cur -= sum[v[idx].second - 1];
			if(cur < 0){
				cou << v[idx].first << " " << v[idx].second << endl;
				cout << sum[v[idx].first - 1] << endl;
				if(v[idx].second) cout << sum[v[idx].second - 1] << endl;
				return 0;
			}
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] = sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((int)a.size())

typedef long long ll;
typedef pair<int, int> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 * 1000 + 10;
const int REM = inf + 7;

set <int> S;
map <int, int> cor;
vector <pi> v;
int dp[2 * MAX_N], sum[2 * MAX_N];
int n, m;

int main(){
	//freopen("in.in", "r", stdin);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	int c = 1;
	cor[0] = 0;
	set <int> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sort(v.begin(), v.end());
	sum[0] = dp[0] = 1;
	int idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			int cur = sum[v[idx].first - 1];
			if(v[idx].second){
				cur -= sum[v[idx].second - 1];
				while(cur < 0) cur += REM;
			}
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] = sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include "iostream"
#include "cstdio"
#include "algorithm"
#include "string"
#include "vector"
#include "cstdlib"
#include "cmath"
#include "map"
#include "queue"
#include "set"
#include "cstring"
#include "complex"

using namespace std;

#define clr(a,b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(b))
#define sz(a) ((ll)a.size())

typedef long long ll;
typedef pair<ll, ll> pi;
typedef complex<double> point;

const double eps=1e-6;
const int inf = (ll)1e9;
const int MAX_N = 100 * 1000 + 100;
const int REM = inf + 7;

set <ll> S;
map <ll, ll> cor;
vector <pi> v;
ll dp[2 * MAX_N], sum[2 * MAX_N];
ll n, m;

int main(){
	//freopen("in.in", "r", stdin);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		ll x, y; cin >> x >> y;
		v.push_back(pi(y, x));
		if(x && x != n) S.insert(x);
		if(y && y != n) S.insert(y);
	}
	ll c = 1;
	cor[0] = 0;
	set <ll> ::iterator it;
	for(it = S.begin(); it != S.end(); it++){
		cor[*it] = c++;
	}
	cor[n] = c++;
	sort(v.begin(), v.end());
	for(int i = 0; i < sz(v); i++){
		v[i].first = cor[v[i].first];
		v[i].second = cor[v[i].second];
	}
	sum[0] = dp[0] = 1;
	ll idx = 0;
	for(int i = 1; i < c; i++){
		for(; idx < sz(v) && v[idx].first == i; idx++){
			ll cur = sum[v[idx].first - 1];
			if(v[idx].second) cur -= sum[v[idx].second - 1];
			dp[i] += cur;
			dp[i] %= REM;
		}
		sum[i] += sum[i - 1] + dp[i];
		sum[i] %= REM;
	}
	cout << dp[c - 1] << endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
using namespace std;
#define Mod 1000000007

typedef pair<int, int> PII;

PII bus[100000];
int x[100001];

struct Node {
    int _a, _b;
    Node *_left, *_right;
    int _sum;
} nodes[200002], *ptr = nodes;

void build(int a, int b) {
    Node *root = ++ptr;
    root->_a = a; root->_b = b;
    root->_sum = 0;
    if (root->_a == root->_b)
        return;
    root->_left = ptr + 1;
    build(a, (a + b) / 2);
    root->_right = ptr + 1;
    build((a + b) / 2 + 1, b);
}

void add(Node *root, int id, int v) {
    root->_sum = (root->_sum + v) % Mod;
    if (root->_a == root->_b)
        return;
    int mid = (root->_a + root->_b) / 2;
    if (id <= x[mid])
        add(root->_left, id, v);
    else
        add(root->_right, id, v);
}

int sum(Node *root, int la, int lb) {
    if (la <= x[root->_a] && x[root->_b] <= lb)
        return root->_sum;
    int ret = 0;
    int mid = (root->_a + root->_b) / 2;
    if (la <= x[mid])
        ret = (ret + sum(root->_left, la, lb)) % Mod;
    if (x[mid + 1] <= lb)
        ret = (ret + sum(root->_right, la, lb)) % Mod;
    return ret;
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &bus[i].second, &bus[i].first);
        x[i] = bus[i].first;
    }
    sort(bus, bus + m);
    if (m == 0 && bus[m - 1].first != n) {
        puts("0");
        return 0;
    }
    x[m] = 0;
    sort(x, x + m + 1);
    int cnt = unique(x, x + m + 1) - x;
    build(0, cnt - 1);
    add(nodes + 1, 0, 1);
    for (int i = 0; i < m; ++i)
        add(nodes + 1, bus[i].first, sum(nodes + 1, bus[i].second, bus[i].first - 1));
    printf("%d\n", sum(nodes + 1, n, n));
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
using namespace std;
#define Mod 1000000007

typedef pair<int, int> PII;

PII bus[100000];
int x[100001];

struct Node {
    int _a, _b;
    Node *_left, *_right;
    int _sum;
} nodes[200002], *ptr = nodes;

void build(int a, int b) {
    Node *root = ++ptr;
    root->_a = a; root->_b = b;
    root->_sum = 0;
    if (root->_a == root->_b)
        return;
    root->_left = ptr + 1;
    build(a, (a + b) / 2);
    root->_right = ptr + 1;
    build((a + b) / 2 + 1, b);
}

void add(Node *root, int id, int v) {
    root->_sum = (root->_sum + v) % Mod;
    if (root->_a == root->_b)
        return;
    int mid = (root->_a + root->_b) / 2;
    if (id <= x[mid])
        add(root->_left, id, v);
    else
        add(root->_right, id, v);
}

int sum(Node *root, int la, int lb) {
    if (la <= x[root->_a] && x[root->_b] <= lb)
        return root->_sum;
    int ret = 0;
    int mid = (root->_a + root->_b) / 2;
    if (la <= x[mid])
        ret = (ret + sum(root->_left, la, lb)) % Mod;
    if (x[mid + 1] <= lb)
        ret = (ret + sum(root->_right, la, lb)) % Mod;
    return ret;
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &bus[i].second, &bus[i].first);
        x[i] = bus[i].first;
    }
    sort(bus, bus + m);
    if (m == 0 || bus[m - 1].first != n) {
        puts("0");
        return 0;
    }
    x[m] = 0;
    sort(x, x + m + 1);
    int cnt = unique(x, x + m + 1) - x;
    build(0, cnt - 1);
    add(nodes + 1, 0, 1);
    for (int i = 0; i < m; ++i)
        add(nodes + 1, bus[i].first, sum(nodes + 1, bus[i].second, bus[i].first - 1));
    printf("%d\n", sum(nodes + 1, n, n));
    return 0;
}


#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

const int mod = 1000000007;

class fenwick {
    private:

    vector<int> t;
    int n;

    public:
    void init (int nn)
    {
        n = nn;
    	t.assign (n, 0);
    }

    int sum (int r)
    {
    	long long result = 0;
    	for (; r >= 0; r = (r & (r+1)) - 1)
    		result += t[r];
    	return result % mod;
    }

    void inc (int i, int delta)
    {
    	for (; i < n; i = (i | (i+1)))
    		t[i] = (t[i] + delta) % mod;
    }

    int sum (int l, int r)
    {
    	return (sum (r) - sum (l-1) + mod) % mod;
    }

    void init (vector<int> a)
    {
    	init ((int) a.size());
    	for (unsigned i = 0; i < a.size(); i++)
    		inc (i, a[i]);
    }
};

int findIndex(vector<int> &ends, int x) {
    int l = -1;
    int r = ends.size() - 1;
    while (r > l + 1) {
        int m = (l + r) / 2;
        if (ends[m] < x) l = m;
        else r = m;
    }
    return r;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > buses(m);
    for (int i = 0; i < m ; i++) {
        int a, b;
        cin >> a >> b;
        buses[i] = make_pair(b, a);
    }
    sort(buses.begin(), buses.end());
    if (buses.back().first < n) { cout << 0; return 0; }

    vector<int> ends;
    ends.push_back(0);
    for (int i = 0 ; i < buses.size() ; i++)
        if (buses[i].first != ends.back()) ends.push_back(buses[i].first);
    fenwick f;
    f.init(ends.size());
    f.inc(0, 1);

    for (int i = 0 ; i < buses.size() ; i++) {
        int s = buses[i].second;
        int t = buses[i].first;

        int si = findIndex(ends, s);
        int ti = findIndex(ends, t);
        if (si >= ti) continue;
        int ways = f.sum(si, ti - 1);
        f.inc(ti, ways);
    }

    int result = f.sum(ends.size() - 1, ends.size() - 1);
    cout << result;
}


#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

const int mod = 1000000007;

class fenwick {
    private:

    vector<int> t;
    int n;

    public:
    void init (int nn)
    {
        n = nn;
        t.assign (n, 0);
    }

    int sum (int r)
    {
    	long long result = 0;
    	for (; r >= 0; r = (r & (r+1)) - 1)
    		result += t[r];
    	return result % mod;
    }

    void inc (int i, int delta)
    {
    	for (; i < n; i = (i | (i+1)))
    		t[i] = (t[i] + delta) % mod;
    }

    int sum (int l, int r)
    {
    	return (sum (r) - sum (l-1) + mod) % mod;
    }

    void init (vector<int> a)
    {
    	init ((int) a.size());
    	for (unsigned i = 0; i < a.size(); i++)
    		inc (i, a[i]);
    }
};

int findIndex(vector<int> &ends, int x) {
    int l = -1;
    int r = ends.size() - 1;
    while (r > l + 1) {
        int m = (l + r) / 2;
        if (ends[m] < x) l = m;
        else r = m;
    }
    return r;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > buses(m);
    for (int i = 0; i < m ; i++) {
        int a, b;
        cin >> a >> b;
        buses[i] = make_pair(b, a);
    }
    sort(buses.begin(), buses.end());
    if (buses.size() == 0 || buses.back().first < n) { cout << 0; return 0; }

    vector<int> ends;
    ends.push_back(0);
    for (int i = 0 ; i < buses.size() ; i++)
        if (buses[i].first != ends.back()) ends.push_back(buses[i].first);
    fenwick f;
    f.init(ends.size());
    f.inc(0, 1);

    for (int i = 0 ; i < buses.size() ; i++) {
        int s = buses[i].second;
        int t = buses[i].first;

        int si = findIndex(ends, s);
        int ti = findIndex(ends, t);
        if (si >= ti) continue;
        int ways = f.sum(si, ti - 1);
        f.inc(ti, ways);
    }

    int result = f.sum(ends.size() - 1, ends.size() - 1);
    cout << result;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const lli MOD = 1000000007;

set<int> SA;
map<int,int> M;
int S[10010], T[10010];

lli F[10010];
lli SF[10010];

vector<int> B[10010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int i = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,i++){
		M[*it]=i;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;
	F[0] = 0;
	SF[0] = 0;
	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			if(F[e]>=MOD)
				F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		if(SF[e]>=MOD)
			SF[e]%=MOD;
	}
	cout << F[N] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const lli MOD = 1000000007;

set<int> SA;
map<int,int> M;
int S[100010], T[100010];

lli F[100010];
lli SF[100010];

vector<int> B[100010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	if(n==0)
	{
		cout << 1 << endl;
		return 0;
	}
	cin >> n >> m;
	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int x = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,x++){
		M[*it]=x;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;
	F[0] = 0;
	SF[0] = 0;
	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			if(F[e]>=MOD)
				F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		if(SF[e]>=MOD)
			SF[e]%=MOD;
	}
	cout << F[N] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const lli MOD = 1000000007;

set<int> SA;
map<int,int> M;
int S[100010], T[100010];

lli F[100010];
lli SF[100010];

vector<int> B[100010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	if(n<=1)
	{
		cout << 1 << endl;
		return 0;
	}
	cin >> n >> m;
	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int x = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,x++){
		M[*it]=x;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;
	F[0] = 0;
	SF[0] = 0;
	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			if(F[e]>=MOD)
				F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		if(SF[e]>=MOD)
			SF[e]%=MOD;
	}
	cout << F[N] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const lli MOD = 1000000007;

set<int> SA;
map<int,int> M;
int S[100010], T[100010];

lli F[100010];
lli SF[100010];

vector<int> B[100010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	if(n<=1)
	{
		cout << 1 << endl;
		return 0;
	}

	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int x = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,x++){
		M[*it]=x;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;
	F[0] = 0;
	SF[0] = 0;
	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			if(F[e]>=MOD)
				F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		if(SF[e]>=MOD)
			SF[e]%=MOD;
	}
	cout << F[N] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const lli MOD = 1000000007;

set<int> SA;
map<int,int> M;
int S[200010], T[200010];

lli F[200010];
lli SF[200010];

vector<int> B[200010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;

	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int x = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,x++){
		M[*it]=x;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;
	F[0] = 0;
	SF[0] = 0;
	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		SF[e]%=MOD;
	}
	while(F[N]<0)
		F[N] += MOD;
	cout << F[N] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const int MOD = 1000000007;
set<int> SA;
map<int,int> M;
int S[10010], T[10010];

lli F[10010];
lli SF[10010];

vector<int> B[10010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int i = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,i++){
		M[*it]=i;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;

	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			if(F[e]>=MOD)
				F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		if(SF[e]>=MOD)
			SF[e]%=MOD;
	}
	cout << F[N] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const lli MOD = 1000000007;

set<int> SA;
map<int,int> M;
int S[10010], T[10010];

lli F[10010];
lli SF[10010];

vector<int> B[10010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int x = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,x++){
		M[*it]=x;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		if(find((B[T[i]]).begin(),(B[T[i]]).end(),S[i])==B[T[i]].end())
			B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;
	F[0] = 0;
	SF[0] = 0;
	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			if(F[e]>=MOD)
				F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		if(SF[e]>=MOD)
			SF[e]%=MOD;
	}
	cout << F[N] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const lli MOD = 1000000007;

set<int> SA;
map<int,int> M;
int S[100010], T[100010];

lli F[100010];
lli SF[100010];

vector<int> B[100010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int x = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,x++){
		M[*it]=x;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;
	F[0] = 0;
	SF[0] = 0;
	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			if(F[e]>=MOD)
				F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		if(SF[e]>=MOD)
			SF[e]%=MOD;
	}
	cout << F[N] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const lli MOD = 1000000007;

set<int> SA;
map<int,int> M;
int S[100010], T[100010];

lli F[100010];
lli SF[100010];

vector<int> B[100010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;

	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int x = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,x++){
		M[*it]=x;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;
	F[0] = 0;
	SF[0] = 0;
	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		SF[e]%=MOD;
	}
	while(F[N]<0)
		F[N] += MOD;
	cout << F[N] << endl;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;

#define iter(c) typeof(c.begin())
#define traverse(it, c) for(iter(c) it = c.begin(); it != c.end(); it++)
#define foreach(x,c) traverse(_I,c)if(bool _B=1)for(typeof(*_I) &x=*_I;_B;_B=0)
typedef long long int lli;

const lli MOD = 1000000007;

set<int> SA;
map<int,int> M;
int S[100010], T[100010];

lli F[100010];
lli SF[100010];

vector<int> B[100010];
int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	if(n<=1)
	{
		cout << 1 << endl;
		return 0;
	}

	SA.insert(0);
	SA.insert(n);
	for (int i = 0; i < m; i++){
		cin >> S[i] >> T[i];
		SA.insert(S[i]);
		SA.insert(T[i]);
	}
	int x = 1;
	for(set<int>::iterator it = SA.begin(); it!=SA.end();it++,x++){
		M[*it]=x;
	}
	int N = SA.size(); // 0 is now 1
	for (int i = 0; i < m; i++){
		S[i] = M[S[i]];
		T[i] = M[T[i]];
//		cout << S[i] << ' ' << T[i] << endl;
		B[T[i]].push_back(S[i]);
	}
//	cout << N << endl;
	F[0] = 0;
	SF[0] = 0;
	F[1] = 1;
	SF[1] = 1;
	for (int e = 2; e <= N; e++){
		F[e] = 0;
		for (int j = 0; j < B[e].size(); j++){
			F[e] += SF[e-1] - SF[B[e][j]-1];
			F[e] %= MOD;
		}
		SF[e] = F[e] + SF[e-1];
		SF[e]%=MOD;
	}
	while(F[N]<0)
		F[N] += MOD;
	cout << F[N] << endl;

}


#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <utility>
using namespace std;

#define MOD 1000000007
#define sz(a) int(a.size())

void solve()
{
    int n, m; cin >> n >> m;
    vector<pair<int,int> > buses(m);
    set<int> terms;
    for(int i=0; i<m; ++i) {
        cin >> buses[i].first >> buses[i].second;
        terms.insert(buses[i].second);
    }
    sort(buses.begin(), buses.end());

    map<int,int> dp;
    for(int i=0; i<sz(buses); ++i) {
        if (buses[i].first >0) break;
        int s=buses[i].first, t=buses[i].second;
        dp[t]++;
    }

    set<int>::iterator it;
    for(it=terms.begin(); it!=terms.end(); ++it)
    for(int i=0; i<sz(buses); ++i) // might TLE here
    {
        int s=buses[i].first, t=buses[i].second;
        if (s<=*it && *it<t) {
            dp[t] = ((long long)dp[t]+dp[*it]) % MOD;
        }
    }
    cout << dp[n] << endl;
}

int main()
{
    solve();
}


#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>
#include <utility>
using namespace std;

#define MOD 1000000007
#define sz(a) int(a.size())

void solve()
{
    int n, m; cin >> n >> m;
    vector<pair<int,int> > buses(m);
    set<int> terms;
    for(int i=0; i<m; ++i) {
        cin >> buses[i].first >> buses[i].second;
        terms.insert(buses[i].second);
    }
    sort(buses.begin(), buses.end());

    map<int,int> dp;
    for(int i=0; i<sz(buses); ++i) {
        if (buses[i].first >0) break;
        int s=buses[i].first, t=buses[i].second;
        dp[t]++;
    }

    set<int>::iterator it;
    for(it=terms.begin(); it!=terms.end(); ++it)
    for(int i=0; i<sz(buses); ++i) // might TLE here
    {
        int s=buses[i].first, t=buses[i].second;
        if (s<=*it && *it<t) {
            dp[t] = ((long long)dp[t]+dp[*it]) % MOD;
        }
    }
    cout << dp[n] << endl;
}

int main()
{
    solve();
}


// prob102D.cpp
// http://codeforces.com/contest/102/problem/D
//
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int,int> pii;

const int N=200000+5;
const int MOD=1000000000+7;
int dp[N];
int sum[N];

int main()
{
    int n,m; cin >> n >> m;
    vector<pii> buses(m);
    for(int i=0; i<m; ++i)
        cin >> buses[i].second>> buses[i].first; //(t[i],s[i])

    sort(buses.begin(), buses.end()); // sort by t[i]

    vector<int> pos; pos.push_back(0); pos.push_back(n);
    for(int i=0; i<m; ++i)
    {
        pos.push_back(buses[i].first);
        pos.push_back(buses[i].second);
    }
    sort(pos.begin(), pos.end());
    pos.resize(unique(pos.begin(),pos.end())-pos.begin());
    sum[0]=0; dp[0]=1; sum[1]=sum[0]+dp[0];
    int busid=0;
    for(int i=1; i<int(pos.size()); ++i)
    {
        dp[i]=0;
        for(; busid<m && buses[busid].first==pos[i]; ++busid)
        {
            int s = buses[busid].second;
            int spos = lower_bound(pos.begin(),pos.end(),s) - pos.begin();
            dp[i] = ((long long)dp[i]+sum[i]-sum[spos]+MOD)%MOD;
        }
        sum[i+1]=((long long)sum[i]+dp[i])%MOD;
    }
    //for(int i=0; i<int(pos.size()); ++i) cout << dp[i] << ' ' << sum[i] << endl;

    int last=int(pos.size())-1;
    int ans = dp[last];
    cout << ans << endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <set>
#include <map>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VI vector<int>
#define VS vector<string>
#define VD vector<double>
#define VVI vector< VI >
#define pb push_back
#define mp make_pair
#define MOD 1000000007

using namespace std;

int n, m;

vector< pair< int, int > > e;
vector< VI > points;

int dp[100010];

int main()
    {
    FOR( i,0 ,100010 )
        dp[i] = -1;
    cin >> n >> m;
    FOR( i, 0, m )
        {
        int a, b; cin >> a >> b;
        e.pb( mp ( a, b ) );
        }

    FOR( i, 0, m )
        {
        VI a1;
        a1.pb( e[i].first );
        a1.pb( -1 );
        a1.pb( i );
        VI a2;
        a2.pb( e[i].second );
        a2.pb( 1 );
        a2.pb( i );
        points.pb( a2 );
        points.pb( a1 ) ;
        }

    sort( points.begin() , points.end() );

    int sol = 0;
    int tmpsum = 0;

    for( int i = (int)( points.size()) - 1; i >= 0; --i )
        {
        int toadd = 0;
        if ( points[i][0] == n )
            {
            dp[points[i][2]] = 1;
            ++tmpsum;
            }
        else if ( points[i][1] == 1 )
            {
            dp[points[i][2]] = tmpsum;
            toadd += tmpsum;
            }
        else if ( points[i][1] == -1 )
            {
            tmpsum -= dp[points[i][2]];
            }
        tmpsum += toadd;

        }

    FOR( i, 0, m )
        if ( e[i].first == 0 )
            sol += dp[i];
    cout << sol << endl;
    return 0;
    }


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <set>
#include <map>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VI vector<int>
#define VS vector<string>
#define VD vector<double>
#define VVI vector< VI >
#define pb push_back
#define mp make_pair
#define MOD 1000000007

using namespace std;

int n, m;

vector< pair< int, int > > e;
vector< VI > points;

long long dp[100010];

int main()
    {
    FOR( i,0 ,100010 )
        dp[i] = -1;
    cin >> n >> m;
    FOR( i, 0, m )
        {
        int a, b; cin >> a >> b;
        e.pb( mp ( a, b ) );
        }

    FOR( i, 0, m )
        {
        VI a1;
        a1.pb( e[i].first );
        a1.pb( -1 );
        a1.pb( i );
        VI a2;
        a2.pb( e[i].second );
        a2.pb( 1 );
        a2.pb( i );
        points.pb( a2 );
        points.pb( a1 ) ;
        }

    sort( points.begin() , points.end() );

    long long sol = 0;
    long long tmpsum = 0;

    for( int i = (int)( points.size()) - 1; i >= 0; --i )
        {
        long long toadd = 0;
        if ( points[i][0] == n )
            {
            dp[points[i][2]] = 1;
            tmpsum = ( tmpsum + 1)%MOD;
            }
        else if ( points[i][1] == 1 )
            {
            dp[points[i][2]] = tmpsum;
            toadd = ( toadd + tmpsum) % MOD;
            }
        else if ( points[i][1] == -1 )
            {
            tmpsum = ( tmpsum - dp[points[i][2]] + MOD) % MOD;
            }
        tmpsum = ( tmpsum + toadd) % MOD;

        }

    FOR( i, 0, m )
        if ( e[i].first == 0 )
            sol = ( sol + dp[i]) % MOD;
    cout << sol << endl;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <set>
#include <map>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VI vector<int>
#define VS vector<string>
#define VD vector<double>
#define VVI vector< VI >
#define pb push_back
#define mp make_pair
#define MOD 1000000007

using namespace std;

int n, m;

vector< pair< int, int > > e;
vector< VI > points;

int dp[100010];

int main()
    {
    FOR( i,0 ,100010 )
        dp[i] = -1;
    cin >> n >> m;
    FOR( i, 0, m )
        {
        int a, b; cin >> a >> b;
        e.pb( mp ( a, b ) );
        }

    FOR( i, 0, m )
        {
        VI a1;
        a1.pb( e[i].first );
        a1.pb( -1 );
        a1.pb( i );
        VI a2;
        a2.pb( e[i].second );
        a2.pb( 1 );
        a2.pb( i );
        points.pb( a2 );
        points.pb( a1 ) ;
        }

    sort( points.begin() , points.end() );

    int sol = 0;
    int tmpsum = 0;

    for( int i = (int)( points.size()) - 1; i >= 0; --i )
        {
        int toadd = 0;
        if ( points[i][0] == n )
            {
            dp[points[i][2]] = 1;
            ++tmpsum;
            }
        else if ( points[i][1] == 1 )
            {
            dp[points[i][2]] = tmpsum;
            toadd = ( toadd + tmpsum) % MOD;
            }
        else if ( points[i][1] == -1 )
            {
            tmpsum = ( tmpsum - dp[points[i][2]] + MOD) % MOD;
            }
        tmpsum = ( tmpsum + toadd) % MOD;

        }

    FOR( i, 0, m )
        if ( e[i].first == 0 )
            sol = ( sol + dp[i]) % MOD;
    cout << sol << endl;
    return 0;
    }


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <set>
#include <map>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VI vector<int>
#define VS vector<string>
#define VD vector<double>
#define VVI vector< VI >
#define pb push_back
#define mp make_pair
#define MOD 1000000007

using namespace std;

int n, m;

vector< pair< int, int > > e;
vector< VI > points;

long long dp[100010];

int main()
    {
    FOR( i,0 ,100010 )
        dp[i] = -1;
    cin >> n >> m;
    FOR( i, 0, m )
        {
        int a, b; cin >> a >> b;
        e.pb( mp ( a, b ) );
        }

    FOR( i, 0, m )
        {
        VI a1;
        a1.pb( e[i].first );
        a1.pb( -1 );
        a1.pb( i );
        VI a2;
        a2.pb( e[i].second );
        a2.pb( 1 );
        a2.pb( i );
        points.pb( a2 );
        points.pb( a1 ) ;
        }

    sort( points.begin() , points.end() );

    long long sol = 0;
    long long tmpsum = 0;
    long long toadd = 0;
    long long last = (1<<30);

    for( int i = (int)( points.size()) - 1; i >= 0; --i )
        {
        if ( last > points[i][0] )
            {
            tmpsum = ( tmpsum + toadd) % MOD;
            toadd = 0;
            }
        if ( points[i][0] == n )
            {
            dp[points[i][2]] = 1;
            tmpsum = ( tmpsum + 1)%MOD;
            }
        else if ( points[i][1] == 1 )
            {
            dp[points[i][2]] = tmpsum;
            toadd = ( toadd + tmpsum) % MOD;
            }
        else if ( points[i][1] == -1 )
            {
            tmpsum = ( tmpsum - dp[points[i][2]] + MOD) % MOD;
            }
        last = points[i][0];
        }

    FOR( i, 0, m )
        if ( e[i].first == 0 )
            sol = ( sol + dp[i]) % MOD;
    cout << sol << endl;
    //system("pause");
    return 0;
    }


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iomanip>
#include <ctime>
using namespace std;

template <typename T>
T next_int() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if (ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * p;
}

const int max_n = (int)2e5 + 228;
const int max_int = (int)1e9 + 228;
const int MOD = (int)1e9 + 7;

map<int, int> b;
pair<int, int> a[max_n];

int dp[max_n];

vector<int> c[max_n];
vector<int> q;

int d[max_n];

void modi(int p, int dl) {
    for(int i = p; i < max_n; i += (i & (-i))) d[i] = (dl + d[i]) % MOD;
}

int get(int p) {
    int ans = 0;
    for(int i = p; i >= 1; i -= (i & (-i))) ans = (ans + d[i]) % MOD;

    return ans;
}

int sum(int l, int r) {
    return (get(r) - get(l - 1) + MOD) % MOD;
}

int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	int n = next_int<int>();
	int m = next_int<int>();

	for(int i = 0; i < m; i++) {
		a[i] = make_pair(next_int<int>(), next_int<int>());

		q.push_back(a[i].first);
		q.push_back(a[i].second);
	}
	q.push_back(0);
	q.push_back(n);

	sort(q.begin(), q.end());

	int k = 1;
	for(int i = 0; i < q.size(); i++) {
		if(i && q[i] != q[i - 1]) k++;

		b[q[i]] = k;
	}

	for(int i = 0; i < m; i++) {
        swap(a[i].first, a[i].second);

		a[i].first = b[a[i].first];
		a[i].second = b[a[i].second];

		c[a[i].second].push_back(a[i].first);
	}

    modi(1, 1);
    dp[1] = 1;

    for(int i = 1; i <= k; i++) {
        for(int j = 0; j < c[i].size(); j++) {
            int pr = dp[i];
            dp[i] = (dp[i] + sum(c[i][j], i - 1)) % MOD;
            modi(i, (dp[i] - pr + MOD) % MOD);
        }
    }

	cout << dp[k] << "\n";
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9
#define rep(i,n) for(int i=0;i<n;i++)

typedef pair<int,int> P;

int n,m,k[200002],s[200002],MOD=1e9+7;
P b[100000];
set<int> S;
set<int>::iterator it;
map<int,int> M;

int main(){
	cin>>n>>m;
	S.insert(0);
	S.insert(n);
	rep(i,m){
		int s,t;
		cin>>s>>t;
		b[i]=make_pair(t,s);
		S.insert(s);
		S.insert(t);
	}
	int cur=0;
	for(it=S.begin();it!=S.end();it++,cur++)M[*it]=cur;
	sort(b,b+m);
	k[0]=s[0]=1;
	int done=0;
	rep(i,m){
		int S=M[b[i].second],T=M[b[i].first];
		if(T>done+1)rep(j,T-done-1){
			k[done+j+1]=0;
			s[done+j+1]=s[done+j];
		}
		done=T;
		k[T]=(k[T]+s[T-1]-(S?s[S-1]:0)+MOD)%MOD;
		s[T]=(s[T-1]+k[T])%MOD;
		if(n>40&&i>50)cout<<k[T]<<" "<<s[T]<<endl;
	}
	cout<<k[M[n]]<<endl;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9
#define rep(i,n) for(int i=0;i<n;i++)

typedef pair<int,int> P;

int n,m,k[200002],s[200002],MOD=1e9+7;
P b[100000];
set<int> S;
set<int>::iterator it;
map<int,int> M;

int main(){
    cin>>n>>m;
    S.insert(0);
    S.insert(n);
    rep(i,m){
        int s,t;
        cin>>s>>t;
        b[i]=make_pair(t,s);
        S.insert(s);
        S.insert(t);
    }
    int cur=0;
    for(it=S.begin();it!=S.end();it++,cur++)M[*it]=cur;
    sort(b,b+m);
    k[0]=s[0]=1;
    int done=0;
    rep(i,m){
        int S=M[b[i].second],T=M[b[i].first];
        if(T>done+1)rep(j,T-done-1){
            k[done+j+1]=0;
            s[done+j+1]=s[done+j];
        }
        done=T;
        k[T]=(k[T]+s[T-1]-(S?s[S-1]:0)+MOD)%MOD;
        s[T]=(s[T-1]+k[T])%MOD;
        if(n>40)cout<<k[T]<<" "<<s[T]<<endl;
    }
    cout<<k[M[n]]<<endl;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9
#define rep(i,n) for(int i=0;i<n;i++)

typedef pair<int,int> P;

int n,m,k[200002],s[200002],MOD=1e9+7;
P b[100000];
set<int> S;
set<int>::iterator it;
map<int,int> M;

int main(){
	cin>>n>>m;
	S.insert(0);
	S.insert(n);
	rep(i,m){
		int s,t;
		cin>>s>>t;
		b[i]=make_pair(t,s);
		S.insert(s);
		S.insert(t);
	}
	int cur=0;
	for(it=S.begin();it!=S.end();it++,cur++)M[*it]=cur;
	sort(b,b+m);
	k[0]=s[0]=1;
	int done=0;
	rep(i,m){
		int S=M[b[i].second],T=M[b[i].first];
		if(T>done+1)rep(j,T-done-1){
			k[done+j+1]=0;
			s[done+j+1]=s[done+j];
		}
		done=T;
		k[T]=(k[T]+s[T-1]-(S?s[S-1]:0))%MOD;
		s[T]=(s[T-1]+k[T])%MOD;
	}
	cout<<k[M[n]]<<endl;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9
#define rep(i,n) for(int i=0;i<n;i++)

typedef pair<int,int> P;

int n,m,k[200002],s[200002],MOD=1e9+7;
P b[100000];
set<int> S;
set<int>::iterator it;
map<int,int> M;

int main(){
	cin>>n>>m;
	S.insert(0);
	S.insert(n);
	rep(i,m){
		int s,t;
		cin>>s>>t;
		b[i]=make_pair(t,s);
		S.insert(s);
		S.insert(t);
	}
	int cur=0;
	for(it=S.begin();it!=S.end();it++,cur++)M[*it]=cur;
	sort(b,b+m);
	k[0]=s[0]=1;
	int done=0;
	rep(i,m){
		int S=M[b[i].second],T=M[b[i].first];
		if(T>done+1)rep(j,T-done-1){
			k[done+j+1]=0;
			s[done+j+1]=s[done+j];
		}
		done=T;
		k[T]=((long long)k[T]+s[T-1]-(S?s[S-1]:0)+MOD)%MOD;
		s[T]=(s[T-1]+k[T])%MOD;
		//if(n>40&&i>50)cout<<k[T]<<" "<<s[T]<<endl;
	}
	cout<<k[M[n]]<<endl;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9
#define rep(i,n) for(int i=0;i<n;i++)

typedef pair<int,int> P;

int n,m,k[200002],s[200002],MOD=1e9+7;
P b[100000];
set<int> S;
set<int>::iterator it;
map<int,int> M;

int main(){
	cin>>n>>m;
	S.insert(0);
	S.insert(n);
	rep(i,m){
		int s,t;
		cin>>s>>t;
		b[i]=make_pair(t,s);
		S.insert(s);
		S.insert(t);
	}
	int cur=0;
	for(it=S.begin();it!=S.end();it++,cur++)M[*it]=cur;
	sort(b,b+m);
	k[0]=s[0]=1;
	int done=0;
	rep(i,m){
		int S=M[b[i].second],T=M[b[i].first];
		if(T>done+1)rep(j,T-done-1){
			k[done+j+1]=0;
			s[done+j+1]=s[done+j];
		}
		done=T;
		k[T]=(k[T]+s[T-1]-(S?s[S-1]:0)+MOD)%MOD;
		s[T]=(s[T-1]+k[T])%MOD;
	}
	cout<<k[M[n]]<<endl;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9
#define rep(i,n) for(int i=0;i<n;i++)

typedef pair<int,int> P;

int n,m,k[200002],s[200002];
P b[100000];
set<int> S;
set<int>::iterator it;
map<int,int> M;

int main(){
	cin>>n>>m;
	S.insert(0);
	S.insert(n);
	rep(i,m){
		int s,t;
		cin>>s>>t;
		b[i]=make_pair(t,s);
		S.insert(s);
		S.insert(t);
	}
	int cur=0;
	for(it=S.begin();it!=S.end();it++,cur++)M[*it]=cur;
	sort(b,b+m);
	k[0]=s[0]=1;
	int done=0;
	rep(i,m){
		int S=M[b[i].second],T=M[b[i].first];
		//cout<<S<<" "<<T<<endl;
		if(T>done+1)rep(j,T-done-1){
			k[done+j+1]=0;
			s[done+j+1]=s[done+j];
		}
		done=T;
		k[T]+=s[T-1]-(S?s[S-1]:0);
		s[T]=s[T-1]+k[T];
	}
	cout<<k[M[n]]<<endl;
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int a[210000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[210000];
int cnt[210000];
int sum[210000];
map<int,int> cnd;
stop st[210000];
vector<int> from[210000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    long long sq=1+(int)sqrt(cnd[n]+1);
    a[0]=1;
    sum[0]=1;
    int l;
    //printf("sq=%lld\n",sq);
    for(int i=1;i<=cnd[n];i++){
        l=i;
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            //cnt[k]++;
            for(int l=k;l<i;){
                if(l%sq==0&&l+sq-1<i){
                    a[i]=(a[i]+sum[l/sq])%1000000007;
                    l+=sq;
                }
                else{
                    a[i]= (a[i]+a[l])%1000000007;
                    l++;
                }
            }
        }
            sum[i/sq]=(sum[i/sq]+a[i])%1000000007;
       // printf("%d %d %d %d\n",i,a[i],i/sq,sum[);

    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnd[110000];
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    a[0]=1;
    for(int i=1;i<=cnd[n];i++){
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            for(int l=k;l<i;l++)a[i]= (a[i]+a[l])%1000000007;
        }
    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnt[110000];
map<int,int> cnd;
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    a[0]=1;
    for(int i=1;i<=cnd[n];i++){
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            cnt[k]++;
            //for(int l=k;l<i;l++)a[i]= (a[i]+a[l])%1000000007;
        }
        long long z=0;
        for(int j=0;j<i;j++){
            z+=cnt[j];
            a[i]=(a[i]+z*a[j]%1000000007)%1000000007;
            cnt[j]=0;
        }
    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
map<int,int> cnd;
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    a[0]=1;
    for(int i=1;i<=cnd[n];i++){
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            for(int l=k;l<i;l++)a[i]= (a[i]+a[l])%1000000007;
        }
    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnt[110000];
int sum[110000];
map<int,int> cnd;
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    long long sq=(int)sqrt(cnd[n]+1);
    a[0]=1;
    sum[0]=1;
    int l;
    //printf("sq=%lld\n",sq);
    for(int i=1;i<=cnd[n];i++){
        l=i;
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            //cnt[k]++;
            for(int l=k;l<i;){
                /*if(l%sq==0&&l+sq-1<i){
                    a[i]=(a[i]+sum[l/sq])%1000000007;
                    l+=sq;
                }
                else{*/
                    a[i]= (a[i]+a[l])%1000000007;
                    l++;
               // }
            }
            sum[i/sq]=(sum[i/sq]+a[i])%1000000007;
        }
       // printf("%d %d %d %d\n",i,a[i],i/sq,sum[);

    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnt[110000];
int sum[110000];
map<int,int> cnd;
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    long long sq=1+(int)sqrt(cnd[n]+1);
    a[0]=1;
    sum[0]=1;
    int l;
    //printf("sq=%lld\n",sq);
    for(int i=1;i<=cnd[n];i++){
        l=i;
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            //cnt[k]++;
            for(int l=k;l<i;){
                if(l%sq==0&&l+sq-1<i){
                    a[i]=(a[i]+sum[l/sq])%1000000007;
                    l+=sq;
                }
                else{
                    a[i]= (a[i]+a[l])%1000000007;
                    l++;
                }
            }
            sum[i/sq]=(sum[i/sq]+a[i])%1000000007;
        }
       // printf("%d %d %d %d\n",i,a[i],i/sq,sum[);

    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnt[110000];
map<int,int> cnd;
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    a[0]=1;
    int l;
    for(int i=1;i<=cnd[n];i++){
        l=i;
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            l=min(l,k);
            cnt[k]++;
            //for(int l=k;l<i;l++)a[i]= (a[i]+a[l])%1000000007;
        }
        long long z=0;
        for(int j=l;j<i;j++){
            z+=cnt[j];
            a[i]=(a[i]+z*a[j]%1000000007)%1000000007;
            cnt[j]=0;
        }
    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnt[110000];
map<int,int> cnd;
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    a[0]=1;
    for(int i=1;i<=cnd[n];i++){
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            cnt[k]++;
            //for(int l=k;l<i;l++)a[i]= (a[i]+a[l])%1000000007;
        }
        int z=0;
        for(int j=0;j<i;j++){
            z+=cnt[j];
            a[i]=(a[i]+z*a[j]%1000000007)%1000000007;
            cnt[j]=0;
        }
    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnt[110000];
int sum[110000];
map<int,int> cnd;
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    long long sq=1+(int)sqrt(cnd[n]+1);
    a[0]=1;
    sum[0]=1;
    int l;
    //printf("sq=%lld\n",sq);
    for(int i=1;i<=cnd[n];i++){
        l=i;
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            //cnt[k]++;
            for(int l=k;l<i;){
                if(l%sq==0&&l+sq-1<i){
                    a[i]=(a[i]+sum[l/sq])%1000000007;
                    l+=sq;
                }
                else{
                    a[i]= (a[i]+a[l])%1000000007;
                    l++;
                }
            }
        }
            sum[i/sq]=(sum[i/sq]+a[i])%1000000007;
       // printf("%d %d %d %d\n",i,a[i],i/sq,sum[);

    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnt[110000];
map<int,int> cnd;
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    a[0]=1;
    for(int i=1;i<=cnd[n];i++){
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            cnt[k]++;
            //for(int l=k;l<i;l++)a[i]= (a[i]+a[l])%1000000007;
        }

        for(int j=0;j<i;j++){
            a[i]=(a[i]+cnt[j]*a[j]%1000000007)%1000000007;
            cnt[j]=0;
        }
    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnd[110000];
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        //ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    a[0]=1;
    for(int i=1;i<=cnd[n];i++){
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            for(int l=k;l<i;l++)a[i]= (a[i]+a[l])%1000000007;
        }
    }
    printf("%d\n",a[cnd[n]]);
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int a[110000];
set<int> s;
struct stop{
    int s,e;
    bool operator < (const stop &o ) const{
        if(e==o.e)return s<o.s;
        return e<o.e;
    }
};
int ind[110000];
int cnt[110000];
int sum[110000];
map<int,int> cnd;
stop st[110000];
vector<int> from[110000];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        stop tmp;
        scanf("%d %d",&tmp.s,&tmp.e);
        //from[tmp.e].push_back(tmp.s);
        st[i]=tmp;
        s.insert(tmp.s);
        s.insert(tmp.e);

    }
    s.insert(0);
    s.insert(n);
    int i=0;
    for(set<int>::iterator it=s.begin();it!=s.end();it++){
        int k=*it;
        ind[i]=k;
        cnd[k]=i;
        i++;
    }
    for(int i=0;i<m;i++){
        from[cnd[st[i].e]].push_back(cnd[st[i].s]);
    }
    //sort(st,st+m);
    //for(int i=0;i<=n;i++)printf("%d %d\n",ind[i],cnd[i]);
    long long sq=(int)sqrt(cnd[n]+1);
    a[0]=1;
    sum[0]=1;
    int l;
    //printf("sq=%lld\n",sq);
    for(int i=1;i<=cnd[n];i++){
        l=i;
        for(int j=0;j<from[i].size();j++){
            int k=from[i][j];
            //cnt[k]++;
            for(int l=k;l<i;){
                if(l%sq==0&&l+sq-1<i){
                    a[i]=(a[i]+sum[l/sq])%1000000007;
                    l+=sq;
                }
                else{
                    a[i]= (a[i]+a[l])%1000000007;
                    l++;
                }
            }
            sum[i/sq]=(sum[i/sq]+a[i])%1000000007;
        }
       // printf("%d %d %d %d\n",i,a[i],i/sq,sum[);

    }
    printf("%d\n",a[cnd[n]]);
}


#include <vector>
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>

//#define __DEBUG__

using namespace std;

static const int MOD = 1000000007;
static const int INF = 1000000000;

inline long long sum(long long a, long long b)
{
	return (a + b)%MOD;
}

struct Segm
{
	int b, e; // coord
	int ind; // ind
	long long v;

	inline Segm(int b_, int e_, int ind_) :
		b(b_), e(e_), ind(ind_), v(0) {}
	inline Segm() :
		b(-1), e(INF), ind(-1), v(0) {}

	inline bool operator <(const Segm& a) const
	{
		return (e < a.e) || (e == a.e && ind < a.ind);
	}
};

class Rmq
{
	public:
		int n;
		vector < Segm > a;

		inline Rmq(int N) :
			a(), n(1)
		{
			while (n < N)
			{
				n *= 2;
			}

			a.resize(2*n, Segm());
		}

		inline Segm& operator [](int ind)
		{
			return a[ind + n];
		}

		inline void update(int ind)
		{
			ind += n;
			while (ind > 1 && ind%2 == 1)
			{
				ind /= 2;
				a[ind].v = sum(a[2*ind].v, a[2*ind + 1].v);
			}
		}

		inline long long select(int begV, int endV)
		{
			int l(n), r(2*n), m;
			while (r - l > 1)
			{
				m = (l + r)/2;
				if (a[m].e < begV)
				{
					l = m;
				} else {
					r = m;
				}
			}
			int beg = r;
			if (l == n && a[l].e >= begV)
			{
				beg = l;
			}

			l = n;
			r = 2*n;
			while (r - l > 1)
			{
				m = (l + r)/2;
				if (a[m].e < endV)
				{
					l = m;
				} else {
					r = m;
				}
			}
			int end = r;
			if (l == n && a[l].e == endV)
			{
				end = l;
			}

#ifdef __DEBUG__
			printf("point_4: %d %d\n", beg, end);
#endif

			return __select(beg, end, n, 2*n, 1);
		}

		inline long long __select(int b, int e, int sb, int se, int ind)
		{
			if (b == e)
			{
				return 0;
			} else if (b == sb && e == se)
			{
				return a[ind].v;
			}

			int sm = (sb + se)/2;
			if (e <= sm)
			{
				return __select(b, e, sb, sm, 2*ind);
			} else if (b >= sm)
			{
				return __select(b, e, sm, se, 2*ind + 1);
			} else {
				return sum(__select(b, sm, sb, sm, 2*ind), __select(sm, e, sm, se, 2*ind + 1));
			}
		}
};

int main()
{
	int N, M;
	cin >> N >> M;

	Rmq r(M);
	for (int i = 0; i < M; ++i)
	{
		r[i].ind = i;
		scanf("%d%d", &r[i].b, &r[i].e);
		if (r[i].b == 0)
		{
			r[i].v = 1;
			r.update(i);
		}
	}

#ifdef __DEBUG__
	printf("point_1\n");
#endif

	sort(r.a.begin() + r.n, r.a.end());

#ifdef __DEBUG__
	printf("point_3\n");
#endif

	for (int i = 0; i < M; ++i)
	{
		r[i].v = sum(r[i].v, r.select(r[i].b, r[i].e));
#if defined(__DEBUG__)
		printf("(%d: %d)\n", i, r[i].v);
#endif
		r.update(i);
	}

#ifdef __DEBUG__
	printf("point_2\n");
#endif

	long long res = 0;
	for (int i = M; i >= 0; --i)
	{
		if (r[i].e == N && r[i].e != INF)
		{
			res = sum(res, r[i].v);
		}
	}

	cout << res << endl;

	return 0;
}


#include <vector>
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

static const long long MOD = 1000000007;

struct Segm
{
	int ind;
	int b, e; // begin, end
	long long v; // variants
};

inline bool operator <(const Segm& a, const Segm& b)
{
	return a.ind < b.ind;
}

vector < Segm > sgm;

struct Point
{
	int c; // coordinate
	int s; // segment
	bool k; // kind

	inline Point(int c_, int s_, bool k_) :
		c(c_), s(s_), k(k_) {}
};

inline bool operator <(const Point& a, const Point& b)
{
	return (a.c < b.c) || (a.c == b.c && ((a.k && !b.k) || ((a.k == b.k && sgm[a.s].e - sgm[a.s].b < sgm[b.s].e - sgm[b.s].b) || ((sgm[a.s].e - sgm[a.s].b == sgm[b.s].e - sgm[b.s].b) && a.s < b.s))));
}

int main()
{
	int N, M;
	cin >> N >> M;

	sgm.resize(M);
	vector < Point > l;
	l.reserve(M*3);
	for (int i = 0; i < M; ++i)
	{
		sgm[i].ind = i;
		sgm[i].v = 0;
		scanf("%d%d", &sgm[i].b, &sgm[i].e);
		l.push_back(Point(sgm[i].b, i, true));
		l.push_back(Point(sgm[i].e, i, false));
	}

	sort(l.begin(), l.end());

	int i_ = 0;
	while (i_ < l.size() && l[i_].c == 0)
	{
		sgm[l[i_].s].v = 1;
		++i_;
	}

	long long sum = 0;
	long long tmp;
	for (int i = 0; i < l.size(); ++i)
	{
		if (l[i].k)
		{
			tmp = sum;
			sgm[l[i].s].v = (sgm[l[i].s].v + sum)%MOD;
			sum = (sum + sgm[l[i].s].v)%MOD;
		} else {
			sum = (sum - sgm[l[i].s].v)%MOD;
		}
	}

	long long res = 0;
	for (int i = l.size() - 1; i >= 0; --i)
	{
		if (l[i].c == N)
		{
			res = (res + sgm[l[i].s].v)%MOD;
		} else {
			break;
		}
	}

	cout << res << endl;

	return 0;
}


#include <vector>
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>

//#define __DEBUG__

using namespace std;

static const int MOD = 1000000007;
static const int INF = 1000000110;

inline long long sum(long long a, long long b)
{
	return (a + b)%MOD;
}

struct Segm
{
	int b, e; // coord
	int ind; // ind
	long long v;

	inline Segm(int b_, int e_, int ind_) :
		b(b_), e(e_), ind(ind_), v(0) {}
	inline Segm() :
		b(-1), e(INF), ind(-1), v(0) {}

	inline bool operator <(const Segm& a) const
	{
		return (e < a.e) || (e == a.e && ind < a.ind);
	}
};

class Rmq
{
	public:
		int n;
		vector < Segm > a;

		inline Rmq(int N) :
			a(), n(1)
		{
			while (n < N)
			{
				n *= 2;
			}

			a.resize(2*n, Segm());
		}

		inline Segm& operator [](int ind)
		{
			return a[ind + n];
		}

		inline void update(int ind)
		{
			ind += n;
			while (ind > 1 && ind%2 == 1)
			{
				ind /= 2;
				a[ind].v = sum(a[2*ind].v, a[2*ind + 1].v);
			}
		}

		inline long long select(int begV, int endV)
		{
			int l(n), r(2*n), m;
			while (r - l > 1)
			{
				m = (l + r)/2;
				if (a[m].e < begV)
				{
					l = m;
				} else {
					r = m;
				}
			}
			int beg = r;
			if (l == n && a[l].e >= begV)
			{
				beg = l;
			}

			l = n;
			r = 2*n;
			while (r - l > 1)
			{
				m = (l + r)/2;
				if (a[m].e < endV)
				{
					l = m;
				} else {
					r = m;
				}
			}
			int end = r;
			if (l == n && a[l].e == endV)
			{
				end = l;
			}

#ifdef __DEBUG__
			printf("point_4: %d %d\n", beg, end);
#endif

			return __select(beg, end, n, 2*n, 1);
		}

		inline long long __select(int b, int e, int sb, int se, int ind)
		{
			if (b == e)
			{
				return 0;
			} else if (b == sb && e == se)
			{
				return a[ind].v;
			}

			int sm = (sb + se)/2;
			if (e <= sm)
			{
				return __select(b, e, sb, sm, 2*ind);
			} else if (b >= sm)
			{
				return __select(b, e, sm, se, 2*ind + 1);
			} else {
				return sum(__select(b, sm, sb, sm, 2*ind), __select(sm, e, sm, se, 2*ind + 1));
			}
		}
};

int main()
{
	int N, M;
	cin >> N >> M;

	Rmq r(M);
	for (int i = 0; i < M; ++i)
	{
		r[i].ind = i;
		scanf("%d%d", &r[i].b, &r[i].e);
		if (r[i].b == 0)
		{
			r[i].v = 1;
			r.update(i);
		}
	}

#ifdef __DEBUG__
	printf("point_1\n");
#endif

	sort(r.a.begin() + r.n, r.a.end());

#ifdef __DEBUG__
	printf("point_3\n");
#endif

	for (int i = 0; i < M; ++i)
	{
		r[i].v = sum(r[i].v, r.select(r[i].b, r[i].e));
#if defined(__DEBUG__)
		printf("(%d: %d)\n", i, r[i].v);
#endif
		r.update(i);
	}

#ifdef __DEBUG__
	printf("point_2\n");
#endif

	long long res = 0;
	for (int i = M; i >= 0; --i)
	{
		if (r[i].e == N && r[i].e != INF)
		{
			res = sum(res, r[i].v);
		}
	}

	cout << res << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define fi(i,a,b)   for(long long i=a;i<=b;i++)
#define fr(i,a)     for(long long i=0;i<a;i++)
#define fd(i,a,b)   for(long long i=b;i>=a;i--)
#define clr(x)      memset(x,0,sizeof(x))
#define cln(x)      memset(x,-1,sizeof(x))
#define __          printf(" ")
#define _           printf("\n")
#define _o          printf("1\n")
#define stree       long long lft=node<<1,rht=(node<<1)|1,mid=(s+e)>>1
#define mod         1000000007
#define read()      freopen("in.txt","r",stdin);
#define write()     freopen("out.txt","w",stdin);

long long s[100010];
long long e[100010];
long long v[100010];
long long a[100010];
long long b[100010];

bool com(long long ix,long long ix2){
   return s[ix]<s[ix2];
}

bool com2(long long ix,long long ix2){
   return e[ix]<e[ix2];
}

main(){
    long long n,m,ans=-1;
    scanf("%lld %lld",&n,&m);
    fr(i,m) scanf("%lld %lld",s+i,e+i),a[i]=i,b[i]=i;
    s[m]=-1,e[m]=-1;a[m]=m;b[m]=m++;
    v[m]=1;s[m]=n;e[m]=n+1;a[m]=m;b[m]=m++;
    sort(a,a+m,com);
    sort(b,b+m,com2);

    long long mem=1,cur=0,i=m-1,j=m-2,val;
    while(s[a[i]]!=-1&&e[b[j]]!=-1){
        val=max(s[a[i]],e[b[j]]);
        if(!val) break;
        cur=0;
        while(val==e[b[j]]) {
                v[b[j]]=mem;
                cur=(cur+mem)%mod,j--;
        }
        while(val==s[a[i]]) mem=(mem-v[a[i]]+mod)%mod,i--;
        mem=(mem+cur)%mod;
    }
    printf("%lld\n",val?0:mem);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define fi(i,a,b)   for(long long i=a;i<=b;i++)
#define fr(i,a)     for(long long i=0;i<a;i++)
#define fd(i,a,b)   for(long long i=b;i>=a;i--)
#define clr(x)      memset(x,0,sizeof(x))
#define cln(x)      memset(x,-1,sizeof(x))
#define __          printf(" ")
#define _           printf("\n")
#define _o          printf("1\n")
#define stree       long long lft=node<<1,rht=(node<<1)|1,mid=(s+e)>>1
#define mod         1000000007
#define read()      freopen("in.txt","r",stdin);
#define write()     freopen("out.txt","w",stdin);

long long s[100010];
long long e[100010];
long long v[100010];
long long a[100010];
long long b[100010];

bool com(long long ix,long long ix2){
   return s[ix]<s[ix2];
}

bool com2(long long ix,long long ix2){
   return e[ix]<e[ix2];
}

main(){
    long long n,m,ans=-1;
    scanf("%lld %lld",&n,&m);
    fr(i,m) scanf("%lld %lld",s+i,e+i),a[i]=i,b[i]=i;
    s[m]=-1,e[m]=-1;a[m]=m;b[m]=m++;
    v[m]=1;s[m]=n;e[m]=n+1;a[m]=m;b[m]=m++;
    sort(a,a+m,com);
    sort(b,b+m,com2);

    long long mem=1,cur=0,i=m-1,j=m-2,val;
    while(s[a[i]]!=-1||e[b[j]]!=-1){
        val=max(s[a[i]],e[b[j]]);
        if(!val) break;
        cur=0;
        while(val==e[b[j]]) {
                v[b[j]]=mem;
                cur=(cur+mem)%mod,j--;
        }
        while(val==s[a[i]]) mem=(mem-v[a[i]]+mod)%mod,i--;
        mem=(mem+cur)%mod;
    }
    printf("%lld\n",val?0:mem);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define fi(i,a,b)   for(long long i=a;i<=b;i++)
#define fr(i,a)     for(long long i=0;i<a;i++)
#define fd(i,a,b)   for(long long i=b;i>=a;i--)
#define clr(x)      memset(x,0,sizeof(x))
#define cln(x)      memset(x,-1,sizeof(x))
#define __          printf(" ")
#define _           printf("\n")
#define _o          printf("1\n")
#define stree       long long lft=node<<1,rht=(node<<1)|1,mid=(s+e)>>1
#define mod         1000000007
#define read()      freopen("in.txt","r",stdin);
#define write()     freopen("out.txt","w",stdin);

long long s[100010];
long long e[100010];
long long v[100010];
long long a[100010];
long long b[100010];

bool com(long long ix,long long ix2){
   return s[ix]<s[ix2];
}

bool com2(long long ix,long long ix2){
   return e[ix]<e[ix2];
}

main(){
    long long n,m,ans=-1;
    scanf("%lld %lld",&n,&m);
    fr(i,m) scanf("%lld %lld",s+i,e+i),a[i]=i,b[i]=i;
    s[m]=-1,e[m]=-1;a[m]=m;b[m]=m++;
    v[m]=1;s[m]=n;e[m]=n+1;a[m]=m;b[m]=m++;
    sort(a,a+m,com);
    sort(b,b+m,com2);

    long long mem=1,cur=0,i=m-1,j=m-2,val;
    while(s[a[i]]!=-1&&e[b[j]]!=-1){
        val=max(s[a[i]],e[b[j]]);
        if(!val) break;
        cur=0;
        while(val==e[b[j]]) {
                v[b[j]]=mem;
                cur=(cur+mem)%mod,j--;
        }
        while(val==s[a[i]]) mem=(mem-v[a[i]]+mod)%mod,i--;
        mem=(mem+cur)%mod;
    }
    printf("%lld\n",mem);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn=100005;
const int Mod =1000000007;

struct node
{
    int s,t;
};

node stop[maxn];
int  e[maxn];
int  f[maxn],sum[maxn];
int  n,m;

bool cmp(node x,node y)
{
    return x.t<y.t;
}

void dp()
{
    int i,k;
    memset(sum,0,sizeof(sum));
    memset(f,0,sizeof(f));
    for (k=1;k<=m;k++)
    {
        int pos=lower_bound(e+1,e+k+1,stop[k].s+1)-&e[0];
        i=stop[k].t;
        if (pos==k) f[i]=1;
        else
        {
            f[i]=(sum[i-1]-sum[stop[pos].t-1]+1)%Mod;
        }
        sum[i]=(sum[i-1]+f[i])%Mod;
    }

    printf("%d\n",f[n]%Mod);

}

int main()
{
    int i;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        for (i=1;i<=m;i++)
            scanf("%d%d",&stop[i].s,&stop[i].t);
        sort(stop+1,stop+m+1,cmp);

        for (i=1;i<=m;i++)
            e[i]=stop[i].t;
        dp();
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn=100005;

struct node
{
    int s,t;
};

node stop[maxn];
int  e[maxn];
int  f[maxn],sum[maxn];
int  n,m;

bool cmp(node x,node y)
{
    return x.t<y.t;
}

void dp()
{
    int i,k;
    memset(sum,0,sizeof(sum));
    memset(f,0,sizeof(f));
    for (k=1;k<=m;k++)
    {
        int pos=lower_bound(e+1,e+k+1,stop[k].s)-&e[0];
        i=stop[k].t;
        if (pos==k) f[i]=1;
        else
        {
            f[i]=sum[i-1]-sum[stop[pos].t-1]+1;
        }
        sum[i]=sum[i-1]+f[i];
    }

    printf("%d\n",f[n]);

}

int main()
{
    int i;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        for (i=1;i<=m;i++)
            scanf("%d%d",&stop[i].s,&stop[i].t);
        sort(stop+1,stop+m+1,cmp);

        for (i=1;i<=m;i++)
            e[i]=stop[i].t;
        dp();
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn=100005;
const int Mod =1000000007;

struct node
{
    int s,t;
};

node stop[maxn];
int  e[maxn];
int  f[maxn],sum[maxn];
int  flag[maxn];
int  n,m;

bool cmp(node x,node y)
{
    return x.t<y.t;
}

void dp()
{
    int i; int ans=0;
    memset(sum,0,sizeof(sum));
    memset(f,0,sizeof(f));
    for (i=1;i<=m;i++)
    {
        int pos=lower_bound(e+1,e+flag[i]+1,stop[i].s)-&e[0];
        if (pos==flag[i]+1) f[i]=0;
        else
        {
            f[i]=(sum[flag[i]]-sum[pos-1])%Mod;
        }

        if (stop[i].s==0) f[i]=(f[i]+1)%Mod;

        sum[i]=(sum[i-1]+f[i])%Mod;

        if (stop[i].t==n)
        {
            ans=(ans+f[i])%Mod;
        }
    }

    printf("%d\n",ans);

}

int main()
{
    int i;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        for (i=1;i<=m;i++)
            scanf("%d%d",&stop[i].s,&stop[i].t);
        sort(stop+1,stop+m+1,cmp);

        for (i=1;i<=m;i++) e[i]=stop[i].t;

        flag[1]=0;
        for (i=2;i<=m;i++)
            if (stop[i].t==stop[i-1].t)
                flag[i]=flag[i-1];
            else
                flag[i]=i-1;
        dp();
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn=100005;
const int Mod =1000000007;

struct node
{
    int s,t;
};

node stop[maxn];
int  e[maxn];
int  f[maxn],sum[maxn];
int  flag[maxn];
int  n,m;

bool cmp(node x,node y)
{
    return x.t<y.t;
}

void dp()
{
    int i; int ans=0;
    memset(sum,0,sizeof(sum));
    memset(f,0,sizeof(f));
    for (i=1;i<=m;i++)
    {
        int pos=lower_bound(e+1,e+flag[i]+1,stop[i].s)-&e[0];
        if (pos==flag[i]+1) f[i]=0;
        else
        {
            f[i]=(sum[flag[i]]-sum[pos-1] + Mod)%Mod;
        }

        if (stop[i].s==0) f[i]=(f[i]+1)%Mod;

        sum[i]=(sum[i-1]+f[i])%Mod;

        if (stop[i].t==n)
        {
            ans=(ans+f[i])%Mod;
        }
    }

    printf("%d\n",ans);

}

int main()
{
    int i;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        for (i=1;i<=m;i++)
            scanf("%d%d",&stop[i].s,&stop[i].t);
        sort(stop+1,stop+m+1,cmp);

        for (i=1;i<=m;i++) e[i]=stop[i].t;

        flag[1]=0;
        for (i=2;i<=m;i++)
            if (stop[i].t==stop[i-1].t)
                flag[i]=flag[i-1];
            else
                flag[i]=i-1;
        dp();
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn=100005;
const int Mod =1000000007;

struct node
{
    int s,t;
};

node stop[maxn];
int  e[maxn];
int  f[maxn],sum[maxn];
int  n,m;

bool cmp(node x,node y)
{
    return x.t<y.t;
}

void dp()
{
    int i; int ans=0;
    memset(sum,0,sizeof(sum));
    memset(f,0,sizeof(f));
    for (i=1;i<=m;i++)
    {
        int pos=lower_bound(e+1,e+i+1,stop[i].s)-&e[0];
        int tmp=lower_bound(e+1,e+i+1,stop[i].t)-&e[0];
        if (pos==i) f[i]=0;
        else
        {
            f[i]=(sum[tmp-1]-sum[pos-1])%Mod;
        }

        if (stop[i].s==0) f[i]=(f[i]+1)%Mod;

        sum[i]=(sum[i-1]+f[i])%Mod;

        if (stop[i].t==n)
        {
            ans=(ans+f[i])%Mod;
        }
    }
    printf("%d\n",ans);

}

int main()
{
    int i;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        for (i=1;i<=m;i++)
            scanf("%d%d",&stop[i].s,&stop[i].t);
        sort(stop+1,stop+m+1,cmp);

        for (i=1;i<=m;i++)
            e[i]=stop[i].t;
        dp();
    }
    return 0;
}


#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
using namespace std;

const int INF = 1000000010;
const bool DEBUG_OUTPUT = false;
const long long modulo = 1000000007;
#define pb push_back
const int go[8][2] = {{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,-1},{1,-1},{-1,1}};

struct pr
{
    int x,y;
    pr(){}
    pr(int x, int y):x(x),y(y) {}
};

bool operator <(pr a, pr b)
{
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return a.x > b.x;
}

bool operator !=(pr a, pr b)
{
    return !(a.x==b.x && a.y==b.y);
}

bool operator ==(pr a,pr b)
{

    return !(a!=b);
}

vector<long long> sums;

long long subsum(int s, int f)
{
    if (f < s) return 0;
    if (s == 0) return sums[f];
    return (modulo + sums[f] - sums[s-1]) % modulo;
}

int main()
{
  //  freopen("tester.in","r",stdin);
  //  freopen("tester.out","w",stdout);

    int n,m;
    scanf("%d%d",&n,&m);
    if (m ==0) {cout << 0; return 0;}
    vector<pr> p(m);

    for (int i = 0; i < m; i++)
        scanf("%d%d",&p[i].x,&p[i].y);

    sort(p.begin(),p.end());

    vector<long long> w(m);
    vector<int> finish(m);

    finish[0] = 0;
    for (int i = 1; i < m; i++)
        if (p[i].y == p[i-1].y) finish[i] = finish[i-1];
        else finish[i] = i-1;

    int ss = m-1;
    for (int i = m-1; i >= 0; i--)

        if (p[i] == p[ss]) w[ss]++;
        else
        {
            w[i] = 1;
            ss = i;

        }

    bool is0 = false, isn = false;
    for (int i = 0; i < m; i++)
    {
        if (p[i].x == 0) is0 = true;
        if (p[i].y == n) isn = true;
    }

    if (!is0 || !isn)
    {
        cout << 0;
        return 0;
    }
    sums.resize(m);
    sums[0] = ((p[0].x == 0)?1:0) * w[0];

    for (int i = 1; i < m; i++)
    {
        int low = p[i].x;
        int s = 0;
        int f = i;
        int ok = -1;
        while (s <= f)
        {
            int key = (s+f)>>1;
            if (p[key].y < low)
            {s = key+1;}
            else
            {
                ok = key;
                f = key-1;
            }
        }
        long long ans = subsum(ok,finish[i]) ;
        if (p[ok].y == p[i].y) ans = 0;
        if (p[i].x == 0) ans++;
        ans = (ans * w[i]) % modulo;

        sums[i] = ((sums[i-1]) + ans) % modulo;
    }

    long long aaa = 0;
    for (int i = m-1; i >= 0; i--)
        if (p[i].y == n)  aaa = (aaa + subsum(i,i)) % modulo;

    cout << aaa;

}


import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author admin
 */
public class NewClass {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int rounds = scan.nextInt();
        HashMap<String, Integer > HM = new HashMap<String, Integer>(1000);

        int maxscore = -999999;
        int ms;
        int index = 0;
        int size = 0;
        String owner;
        String winner=null;
        for (int i = 0; i < rounds; i++) {
            String name = scan.next();
            int  score = scan.nextInt();
            if (i==0)
            {maxscore=score;
                 winner=name;
            }
            else
            {
            maxscore = Collections.max(HM.values());
            }
            if (HM.containsKey(name)) {

                int previos_score = HM.remove(name);

                    HM.put(name, score + previos_score);
                if(HM.get(name)>maxscore)
                {
                    winner=name;
                }

            } else {
                HM.put(name, score);

                if(HM.get(name)>maxscore)
                {
                    winner=name;
                }
            }

        }

        Map<String, Integer> mp;

//        mp = HM;

//        for (Entry<String, Integer> entry : mp.entrySet()) {
//            if (entry.getValue() == maxscore) {
////                winner="";
////             winner =entry.getKey();
//
//
//            }
//
//        }
System.out.println(winner);

    }
}


9
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int rounds = scan.nextInt();
        Wins[] records = new Wins[rounds + 1];
        Wins[] record2 = new Wins[rounds + 1];
        int maxscore = -99999;
        int index = 0;
        int size=0;
        for (int i = 0; i < rounds; i++) {
            String name = scan.next();
            int score = scan.nextInt();

            if (i == 0) {
                records[0] = new Wins(score, name);
                maxscore = score;
                size++;
            } else {
                boolean flage = false;
                for (int o = 0; o < size; o++) {

                    if (name.equals(records[o].name)) {
                        flage = true;
                        records[o].score = records[o].score + score;
                        if (maxscore < records[o].score) {
                            maxscore = records[o].score;
                            index = o;
                        }

                    }
                    if (flage) {
                        break;
                    }

                }
                if (!flage) {
                    records[i] = new Wins(score, name);
                    size++;
                    if (maxscore < score) {
                        maxscore = score;
                        index = i;
                    }

                }

            }
        }
        System.out.println(records[index].name);

    }
}

class Wins {

    int score;
    String name;
    int index;

    public Wins(int score, String name, int index) {
        this.score = score;
        this.name = name;
        this.index = index;
    }

    public Wins(int score, String name) {
        this.score = score;
        this.name = name;
        this.index = 0;
    }
}