Statues

Time limit: 0.5s Memory limit: 256MB Input: Output:

“Lulu was one of the picturesque characters of Cluj in the 70s and 90s. More recognizable than most personalities of the time. He deserves to be remembered by a statue at the bus station.”

The Info(1)cup Kingdom consists of nn towns, numbered from 11 to nn. Lulu dreams of being the ruler of the Info(1)cup Kingdom, so he began making plans to honour himself before he even becomes the ruler. He wants to build statues of himself in all of the towns, however he doesn’t want to be too suspicious. As a consequence, he will build only one statue each day. On day ii he will build a statue in town did_i. Moreover, he must satisfy qq different restrictions of type (x,y)(x, y), meaning that all of the statues in the towns from xx to yy must be built after all of the statues in the towns from 11 to x1x-1. He is now wondering how many ways are there to build such statues in the nn towns, modulo 1 000 0031 \ 000 \ 003.

Input data

The first line of the input will contain integers nn and qq, the number of towns and the number of restrictions respectively. The next qq lines each contain a restriction of type (x,y)(x, y).

Output data

Output the number of ways to build the statues in the towns, modulo 1 000 0031 \ 000 \ 003. In other words, output the remainder of the number of ways to build statues in the towns when divided by 1 000 0031 \ 000 \ 003.

Restrictions

  • 1n10101 ≤ n ≤ 10^{10}
  • 1q2×1051 ≤ q ≤ 2 \times 10^5
  • 1xyn1 ≤ x ≤ y ≤ n

Subtask 1 (7 points)

  • n9n ≤ 9

Subtask 2 (11 points)

  • n17n ≤ 17

Subtask 3 (6 points)

  • q=1q = 1

Subtask 4 (9 points)

  • n106n ≤ 10^6 and y=ny = n for each restriction

Subtask 5 (15 points)

  • n106n ≤ 10^6 and yi<xi+1y_i < x_{i+1} for all 1i<q1 ≤ i < q

Subtask 6 (25 points)

  • n106n ≤ 10^6

Subtask 7 (27 points)

  • No further restrictions

Examples

stdin

4 1
2 3

stdout

8

stdin

63 3
26 63
6 58
33 48

stdout

222492

Explanations

These are all of the ways Lulu can build the statues in the nn towns.

  1. d = ⟨1, 2, 3, 4⟩
  2. d = ⟨1, 2, 4, 3⟩
  3. d = ⟨1, 4, 2, 3⟩
  4. d = ⟨4, 1, 2, 3⟩
  5. d = ⟨1, 3, 2, 4⟩
  6. d = ⟨1, 3, 4, 2⟩
  7. d = ⟨1, 4, 3, 2⟩
  8. d = ⟨4, 1, 3, 2⟩

Log in or sign up to be able to send submissions!