1 #include<iostream>
2 #include<string>
3 #include<algorithm>
4 #include<cstdio>
5 #include<cstring>
6 #include<cstdlib>
7 #include<cmath>
8 using namespace std;
9 typedef long long s64;
10
11 const int ONE = 5000005;
12 const int MOD = 1e9 + 7;
13
14 int n, m;
15 int x, y;
16 int fac[ONE], inv[ONE];
17 int f[ONE];
18
19 struct point
20 {
21 int x, y;
22 }a[ONE];
23 bool cmp(const point &a, const point &b)
24 {
25 if(a.x != b.x) return a.x < b.x;
26 return a.y < b.y;
27 }
28
29 int get()
30 {
31 int res=1,Q=1; char c;
32 while( (c=getchar())<48 || c>57)
33 if(c==‘-‘)Q=-1;
34 if(Q) res=c-48;
35 while((c=getchar())>=48 && c<=57)
36 res=res*10+c-48;
37 return res*Q;
38 }
39
40 int Quickpow(int a, int b)
41 {
42 int res = 1;
43 while(b)
44 {
45 if(b & 1) res = (s64)res * a % MOD;
46 a = (s64)a * a % MOD;
47 b >>= 1;
48 }
49 return res;
50 }
51
52 void Deal_first()
53 {
54 fac[0] = 1;
55 for(int i = 1; i <= 2 * n; i++)
56 fac[i] = (s64)fac[i - 1] * i % MOD;
57 inv[2 * n] = Quickpow(fac[2 * n], MOD - 2);
58 for(int i = 2 * n - 1; i >= 0; i--)
59 inv[i] = (s64)inv[i + 1] * (i + 1) % MOD;
60 }
61
62 int C(int n, int m)
63 {
64 if(n < 0 || m < 0) return 0;
65 return (s64)fac[n] * inv[m] % MOD * inv[n - m] % MOD;
66 }
67
68 void Modit(int &a)
69 {
70 if(a < 0) a += MOD;
71 if(a >= MOD) a -= MOD;
72 }
73
74 int Ways(point a, point b)
75 {
76 if(n < 0 || m < 0) return 0;
77 return C(b.y - a.y + b.x - a.x, b.y - a.y);
78 }
79
80 int Getit(point a, point b)
81 {
82 return Ways(a, b) - Ways(a, (point){b.y - 1, b.x + 1});
83 }
84
85 int main()
86 {
87 n = get(); m = get();
88 Deal_first();
89
90 for(int i = 1; i <= m; i++)
91 a[i].x = get(), a[i].y = get();
92
93 a[++m] = (point){n, n};
94 sort(a + 1, a + m + 1, cmp);
95
96 for(int i = 1; i <= m; i++)
97 {
98 Modit(f[i] = Getit((point){0, 0}, a[i]));
99 for(int j = 1; j < i; j++)
100 Modit(f[i] -= (s64)f[j] * Getit(a[j], a[i]) % MOD);
101 }
102
103 printf("%d", f[m]);
104 }