Kaldorian Knights

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

The king of Kaldoria traditionally celebrates his birthday by inviting the knights of his realm to a big jousting tournament, and every noble house participates by sending their best knights to win fame and glory. At the end of the tournament, the king does not only choose a winner but ranks all nn knights from worst to best.

The number of knights belonging to house ii is denoted by k_ik\_i. Each knight serves at most one house. There can be knights who do not serve any house. The houses are ordered by their influence in the kingdom (with the first one being the most influential). If the k_1k\_1 knights of the most powerful house take the last k_1k\_1 places in the tournament, the house will incite a revolt against king and crown. The members of the second most influential house are not that powerful. Even if all its k_2k\_2 knights end up at the bottom of the ranking, it would be considered a strong provocation but the house would not be able to start a revolt. However, if the last k_1+k_2k\_1 + k\_2 places are taken by all the knights of the two most influential houses combined, then the two houses will unite and start fighting the king. More generally, if the knights of the \ell most powerful houses occupy the last k_1+k_2++k_k\_1 + k\_2 + \dots + k\_\ell places in the tournament, they will unite and incite a revolt.

Of course, a revolt has to be avoided at all cost. Knowing that the king often chooses the ranking spontaneously and without too much consideration, the chief mathematician of the crown has been tasked with analysing how many rankings will not lead to a revolt.

입력

The input consists of:

  • One line with integers nn (1n1061 \leq n \leq 10^6) and hh (0h50000 \leq h \leq 5000), the number of knights and the number of houses.
  • hh lines, with the iith line containing an integer k_ik\_i (1k_in1 \leq k\_i \leq n), denoting the number of knights from house ii. Note that every house is represented by at least one knight.

It holds that _i=1hk_in\sum\_{i=1}^h k\_i \leq n.

출력

Output the number of rankings that do not lead to a revolt. As this number can be quite large, it should be output modulo 109+710^9+7.