Under construction

Still being built. Things may change

Integers and Ranges

Time limit3sMemory limit512 MB

Summary
Count the digit strings of length n where the product of digits in every given range is divisible by 9, modulo 1e9+7.
Level

Medium6 of 10

Topics
Dynamic programming, Intervals, Number theory
Solved
No attempts yet

Problem

Time limit: 3000 ms. Memory limit: 512 MB.

Isaac has a decimal integer a1a2…an‾\overline{a_1 a_2 \dots a_n}, possibly with leading zeroes. He knows that for mm ranges [l1,r1],[l2,r2],…,[lm,rm][l_1, r_1], [l_2, r_2], \dots, [l_m, r_m], the product ali×ali+1×⋯×ari mod 9=0a_{l_i} \times a_{l_i + 1} \times \dots \times a_{r_i} \bmod 9 = 0 holds for each range ii. Find the number of valid integers a1a2…an‾\overline{a_1 a_2 \dots a_n}, modulo (109+7)(10^9+7).

Input

The input consists of several test cases and ends at end-of-file.

The first line of each test case contains two integers nn and mm. The next mm lines each contain two integers lil_i and rir_i.

Output

For each test case, print one integer, the result.

Constraints

  • 1≤n,m≤1031 \leq n, m \leq 10^3
  • 1≤li≤ri≤n1 \leq l_i \leq r_i \leq n
  • There are at most 100100 test cases.

Examples1

  1. Example 1

    Input
    2 1
    1 2
    4 2
    1 3
    2 4
    50 1
    1 50
    
    Expected output
    40
    4528
    100268660