Under construction

Still being built. Things may change

Keep It Cool

Time limit1sMemory limit512 MB

Summary
Count permutations of all pairs (a, b) with a < b that satisfy the betweenness rule for every triple and m given order constraints, modulo 998244353.
Level

Hard8 of 10

Topics
Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

Consider the set of all pairs (a,b)(a, b) where aa and bb satisfy 1≤a<b≤n1 \leq a < b \leq n. A permutation of all these pairs is called balanced if, for any aa, bb, and cc with 1≤a<b<c≤n1 \leq a < b < c \leq n, the pair (a,c)(a, c) lies between the pairs (a,b)(a, b) and (b,c)(b, c) in the permutation. That is, the three pairs appear either in the order (a,b),(a,c),(b,c)(a, b), (a, c), (b, c), or in the order (b,c),(a,c),(a,b)(b, c), (a, c), (a, b).

There are also mm additional restrictions. The ii-th restriction requires the pair (ai,bi)(a_i, b_i) to appear before the pair (ci,di)(c_i, d_i) in the permutation. Count the balanced permutations that satisfy all mm restrictions.

Input

The first line contains two integers nn and mm (2≤n≤102 \le n \le 10, 0≤m≤100 \le m \le 10). Each of the following mm lines contains four integers aia_i, bib_i, cic_i, and did_i (1≤ai<bi≤n1 \le a_i < b_i \le n, 1≤ci<di≤n1 \le c_i < d_i \le n). The pairs (ai,bi)(a_i, b_i) and (ci,di)(c_i, d_i) are distinct.

Output

Print the number of balanced permutations where (ai,bi)(a_i, b_i) appears before (ci,di)(c_i, d_i) for every ii, modulo the prime 998 244 353998\,244\,353.

Hint

In the second sample, the valid permutations are (1,2),(1,3),(1,4),(2,3),(2,4),(3,4)(1,2), (1,3), (1,4), (2,3), (2,4), (3,4) and (1,2),(1,3),(2,3),(1,4),(2,4),(3,4)(1,2), (1,3), (2,3), (1,4), (2,4), (3,4).

Examples2

  1. Example 1

    Input
    2 0
    
    Expected output
    1
    
  2. Example 2

    Input
    4 3
    1 2 2 3
    1 2 3 4
    2 3 3 4
    
    Expected output
    2