Under construction

Still being built. Things may change

Sunwoo's Setlist

Interview

Time limit1sMemory limit512 MB

Summary
Count the ordered song sequences, with repeats allowed, whose running times sum to exactly N minutes, modulo 1,000,000,007.
Level

Medium5 of 10

Topics
Dynamic programming, Math
Solved
No attempts yet

Problem

Sunwoo wants to dazzle the students of Ajou University with a rousing live performance at the university's first festival in three years. Sunwoo plans a performance of exactly NN (1≤N≤10181\leq N \leq 10^{18}) minutes, but has not yet decided which songs to play, in what order, or how many times each one should be played.

For example, suppose there are these candidate songs: 1. , Peace like an Ajou River, 3 minutes; 2. , Compsci Boy, 2 minutes; 3. , Brown Earrings, 1 minute; 4. , Not Easy, 5 minutes; 5. , Yoda, 4 minutes.

If Sunwoo builds a 10-minute show from these songs, a valid performance is [3, 1, 3, 4], meaning songs 3, 1, 3, and 4 in that order. As this shows, Sunwoo never takes a break in the middle! The same song may be played several times, and some candidates may not be used at all. The ordered list of songs played in a performance is called a setlist.

Given the number of candidate songs and the running time of each one, help Sunwoo count the setlists that make a performance of exactly NN minutes.

Input

The first line contains NN (1≤N≤10181 \leq N \leq 10^{18}) and MM (2≤M≤100 0002 \leq M \leq 100\,000), separated by a space, where MM is the number of candidate songs. Each of the next MM lines contains the running time tit_i (1≤i≤M1 \leq i \leq M, 1≤ti≤51 \leq t_i \leq 5) of song ii.

Output

Print the number of possible setlists modulo 1 000 000 0071\,000\,000\,007 (=109+7=10^9+7). If no setlist can be formed, the answer is 00.

Examples2

  1. Example 1

    Input
    25 5
    5
    5
    5
    5
    5
    
    Expected output
    3125
    
  2. Example 2

    Input
    10 6
    2
    2
    2
    3
    4
    4
    
    Expected output
    555