//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
ll pwr(ll base, ll p, ll mod=MOD){
base %= mod;
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
ll gcd(ll a, ll b){
if(b == 0) return a;
return gcd(b, a%b);
}
const int N = 200002;
int n, sparse[20][N];
ll DP[N];
int rmq(int l, int r){
int k = log2(r-l+1);
return min(sparse[k][l], sparse[k][r-(1<<k)+1]);
}
int main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0);
int q;
scanf("%d%d", &n, &q);
for(int i=1;i<=n;i++)
sparse[0][i] = n+1;
while(q--){
int l, r;
scanf("%d%d", &l, &r);
sparse[0][l] = min(sparse[0][l], r);
}
for(int j=1;(1<<j)<=n;j++)
for(int i=1;i+(1<<j)-1<=n;i++)
sparse[j][i] = min(sparse[j-1][i], sparse[j-1][i+(1<<(j-1))]);
DP[n+1] = 1;
for(int i=n;i>=1;i--){
int max_allowed = i, lo = i, hi = n;
while(lo <= hi){
int mid = (lo+hi)/2;
if(rmq(i, mid) >= mid){
max_allowed = max(max_allowed, mid);
lo = mid+1;
}
else{
hi = mid-1;
}
}
ll temp = DP[i+1] - DP[max_allowed+2];
if(rmq(i, n) == n+1) temp++;
DP[i] = (DP[i+1] + temp) % MOD;
}
ll ans = (DP[1]-DP[2]+MOD) % MOD;
printf("%lld\n", ans);
return 0;
}
Ly9zYXR5YWtpMzc5NAojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBmZiBmaXJzdAojZGVmaW5lIHNzIHNlY29uZAojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIE1PRCAoMTAwMDAwMDAwN0xMKQojZGVmaW5lIExFRlQobikgKDIqKG4pKQojZGVmaW5lIFJJR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9bjtpKyspCiAgICAgICAgICAgIHNwYXJzZVtqXVtpXSA9IG1pbihzcGFyc2Vbai0xXVtpXSwgc3BhcnNlW2otMV1baSsoMTw8KGotMSkpXSk7CgogICAgRFBbbisxXSA9IDE7CiAgICBmb3IoaW50IGk9bjtpPj0xO2ktLSl7CiAgICAgICAgaW50IG1heF9hbGxvd2VkID0gaSwgbG8gPSBpLCBoaSA9IG47CiAgICAgICAgd2hpbGUobG8gPD0gaGkpewogICAgICAgICAgICBpbnQgbWlkID0gKGxvK2hpKS8yOwogICAgICAgICAgICBpZihybXEoaSwgbWlkKSA+PSBtaWQpewogICAgICAgICAgICAgICAgbWF4X2FsbG93ZWQgPSBtYXgobWF4X2FsbG93ZWQsIG1pZCk7CiAgICAgICAgICAgICAgICBsbyA9IG1pZCsxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICBoaSA9IG1pZC0xOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGxsIHRlbXAgPSBEUFtpKzFdIC0gRFBbbWF4X2FsbG93ZWQrMl07CiAgICAgICAgaWYocm1xKGksIG4pID09IG4rMSkgIHRlbXArKzsKICAgICAgICBEUFtpXSA9IChEUFtpKzFdICsgdGVtcCkgJSBNT0Q7CiAgICB9CgogICAgbGwgYW5zID0gKERQWzFdLURQWzJdK01PRCkgJSBNT0Q7CiAgICBwcmludGYoIiVsbGRcbiIsIGFucyk7CiAgICByZXR1cm4gMDsKfQoKCgoKCgoK