Good Game

n차원에서 정렬된 목표점까지 좌표가 비감소하는 단조 격자 경로 중 주어진 정렬 장애물 m개를 피하는 경로 수를 1e9+7로 나눈 나머지로 구한다.

어려움8조합론동적 계획법수학아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You want to walk from (0,0,,0)(0, 0, \ldots, 0) to (a_0,a_1,,a_n1)(a\_0, a\_1, \ldots, a\_{n - 1}) in an nn-dimensional space. On each step, you can increase one component of your coordinate vector by one. There are mm obstacles p_1,p_2,,p_mp\_1, p\_2, \ldots, p\_m. You want to find the number of paths that don't pass through the obstacles.

However, this problem is too simple for an ICPC contest in the year 8102. We add one more constraint. For every point (x_0,x_1,,x_n1)(x\_0, x\_1, \ldots, x\_{n - 1}) on your path, the components of this vector should be non-decreasing: x_0x_1x_n1x\_0 \leq x\_1 \leq \ldots \leq x\_{n - 1}.

Output the number of paths modulo 109+710^9 + 7.

입력

The first line contains two integers nn and mm (1n501 \leq n \leq 50, 0m500 \leq m \leq 50).

The second line contains nn integers a_0,a_1,,a_n1a\_0, a\_1, \ldots, a\_{n-1} (0a_0a_1a_n11040 \leq a\_0 \leq a\_1 \leq \ldots \leq a\_{n-1} \leq 10^4), the coordinate vector of your destination.

The following mm lines describe obstacles. The ii-th of these lines contains nn integers p_i,0,p_i,1,,p_i,n1p\_{i, 0}, p\_{i, 1}, \ldots, p\_{i, n - 1} (0p_i,0p_i,1p_i,n1104)0 \leq p\_{i, 0} \leq p\_{i, 1} \leq \ldots \leq p\_{i, n - 1} \leq 10^4), the coordinate vector of an obstacle.

The starting point, destination, and all the obstacles are distinct.

출력

Output the answer modulo 109+710^9 + 7.