“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 towns, numbered from to . 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 he will build a statue in town . Moreover, he must satisfy different restrictions of type , meaning that all of the statues in the towns from to must be built after all of the statues in the towns from to . He is now wondering how many ways are there to build such statues in the towns, modulo .
Input data
The first line of the input will contain integers and , the number of towns and the number of restrictions respectively. The next lines each contain a restriction of type .
Output data
Output the number of ways to build the statues in the towns, modulo . In other words, output the remainder of the number of ways to build statues in the towns when divided by .
Restrictions
Subtask 1 (7 points)
Subtask 2 (11 points)
Subtask 3 (6 points)
Subtask 4 (9 points)
- and for each restriction
Subtask 5 (15 points)
- and for all
Subtask 6 (25 points)
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 towns.
- d = ⟨1, 2, 3, 4⟩
- d = ⟨1, 2, 4, 3⟩
- d = ⟨1, 4, 2, 3⟩
- d = ⟨4, 1, 2, 3⟩
- d = ⟨1, 3, 2, 4⟩
- d = ⟨1, 3, 4, 2⟩
- d = ⟨1, 4, 3, 2⟩
- d = ⟨4, 1, 3, 2⟩