There is a row of N houses labeled 1…N from left to right. You start in house 1, and you can move only by teleporting. In order to teleport from house X to house Y, you must wait at least |X−Y| units of time (possibly more) before instantaneously teleporting to house Y. It is not allowed to teleport from a house to the same house.
There are K parties in the houses at various points in time, and you want to attend all of them. The ith party takes place at house xi and at time ti, and to attend this party, you must reach house xi at exactly time ti. You are allowed to revisit houses, but you are not allowed to wait at a house until a party there begins. There may be multiple parties at a house, although at different times, and there may be multiple parties at a single time, although at different houses.
Define a teleportation sequence as an ordered list of pairs (a,b) indicating the position and time of reaching of a house respectively, ordered in chronological order. The pair (1,0) is the beginning of every teleportation sequence.
How many distinct teleportation sequences are there which allow you to attend all the parties, modulo 1,000,000,007 (109+7)?
Input Format :
The first line of input contains three space-separated integers, N,T (the time of the last party), and K.
The next K lines of input each contain two space-separated integers, xi and ti.
Output Format :
Print the number of distinct teleportation sequences which visit all the parties, modulo 1,000,000,007 (109+7).
Constraints :
1≤N,T,K≤5000
1≤xi≤N
1≤ti≤T
There will be at least one party taking place at time T.
It is guaranteed that there are no two indices i and j, i≠j, such that xi=xj and ti=tj both hold true.
The two valid teleportation sequences are:
Note how the first sequence revisits house 2 and is allowed, but the sequence (1,0)→(2,2) is not allowed both because it doesn't visit all the parties and because it waits for the second party.