Permutation Counting
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

You are given an integer n, and m pairs of integers with distinct x_i, i.e. for all . You need to find the number of permutation p of length n satisfying for all i. Since the number might be too large, you only need to output the answer modulo .

Recall that a permutation of length n is a sequence of length n and contains exactly once. For instance, and are permutations while and are not.

输入描述:

The first line contains two integers  and , indicating the length of the permutation and the number of constraints.

The i-th of the following m lines contains two integers and indicating the constraint that . It is guaranteed that all x_i are distinct.

输出描述:

Output an integer indicating the number of permutations satisfying the conditions modulo .
示例1

输入

复制
3 1
1 2

输出

复制
3

说明

In the first sample, all valid permutations are \{1,2,3\},\{1,3,2\} and \{2,3,1\}, so the answer is 3.
示例2

输入

复制
3 2
1 2
2 3

输出

复制
1
示例3

输入

复制
3 2
1 2
2 1

输出

复制
0
示例4

输入

复制
10 7
1 2
3 2
5 4
7 8
2 6
4 6
8 6

输出

复制
37800