Problem:
Score : 100 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns.
Let (i, j) denote the square at the i-th row from the top and the j-th column from the left.

In the grid, N Squares (r_1, c_1), (r_2, c_2), \ldots, (r_N, c_N) are wall squares, and the others are all empty squares.
It is guaranteed that Squares (1, 1) and (H, W) are empty squares.

Taro will start from Square (1, 1) and reach (H, W) by repeatedly moving right or down to an adjacent empty square.

Find the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.

Constraints

All values in input are integers.

2 \leq H, W \leq 10^5

1 \leq N \leq 3000

1 \leq r_i \leq H

1 \leq c_i \leq W

Squares (r_i, c_i) are all distinct.

Squares (1, 1) and (H, W) are empty squares.

Input

Input is given from Standard Input in the following format:

H W N
r_1 c_1
r_2 c_2
:
r_N c_N

Output

Print the number of Taro's paths from Square (1, 1) to (H, W), modulo 10^9 + 7.

Sample Input 1

3 4 2
2 2
1 4

Sample Output 1

3

There are three paths as follows:

Sample Input 2

5 2 2
2 1
4 2

Sample Output 2

0

There may be no paths.

Sample Input 3

5 5 4
3 1
3 5
1 3
5 3

Sample Output 3

24

Sample Input 4

100000 100000 1
50000 50000

Sample Output 4

123445622

Be sure to print the count modulo 10^9 + 7.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ll long long int
#define ld double
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define be begin
#define sz(a) (ll)a.size()
#define INF 1e18
 
typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
 
ll mod=1e9+7;
// ll gcd(ll a, ll b){
//     if(a<b) swap(a,b);
//     if(b==0) return a;
//     return gcd(b,a%b);
// }
 
ll fun(ll x, ll y){
    ll rem=1;
    while(y!=0){
        if(y%2==1){
            rem=(rem*x)%mod;
        }
        x=(x*x)%mod;
        y/=2;
    }
    return rem;
}

ll fact[200001];
ll ifact[200001];
ll dp[3001]={0};

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll h,w,n;
	cin>>h>>w>>n;
	fact[0]=1; ifact[0]=1;
	for(ll i=1;i<=(h+w);i++) fact[i]=(fact[i-1]*i)%mod;
	for(ll i=1;i<=(h+w);i++) ifact[i]=fun(fact[i],mod-2);
	ve<pi>ar(n+1);
	lr(n){
		cin>>ar[i].fi>>ar[i].se;
		ar[i].fi--; ar[i].se--;
	}
	ar[n]=mk(h-1,w-1);
	sort(all(ar));
	for(ll i=0,y,a,b;i<=n;i++){
		dp[i]=fact[ar[i].fi+ar[i].se]*ifact[ar[i].fi]%mod*ifact[ar[i].se]%mod;
		for(ll j=i-1;j>=0;j--){
			if(ar[j].se>ar[i].se) continue;
			a=ar[i].fi-ar[j].fi;b=ar[i].se-ar[j].se;
			y=fact[a+b]*ifact[a]%mod*ifact[b]%mod;
			dp[i]=(dp[i]+mod-dp[j]*y%mod)%mod;
		}
	}
	cout << dp[n] << "\n";
	return 0;
}