#AGC056B. [AGC056B] Range Argmax

[AGC056B] Range Argmax

Score : 900900 points

Problem Statement

Given are an integer NN and MM pairs of integers. The ii-th pair is (Li,Ri)(L_i,R_i).

Find the number of integer sequences x=(x1,x2,,xM)x=(x_1,x_2,\cdots,x_M) that can be generated as follows, modulo 998244353998244353.

  • Provide a permutation p=(p1,p2,,pN)p=(p_1,p_2,\cdots,p_N) of (1,2,,N)(1,2,\cdots,N).
  • For each ii (1iM1 \leq i \leq M), let xix_i be the index of the largest element among pLi,pLi+1,,pRip_{L_i},p_{L_i+1},\cdots,p_{R_i}. That is, max(pLi,pLi+1,,pRi)=pxi\max(p_{L_i},p_{L_i+1},\cdots,p_{R_i})=p_{x_i}.

Constraints

  • 2N3002 \leq N \leq 300
  • 1MN(N1)/21 \leq M \leq N(N-1)/2
  • 1Li<RiN1 \leq L_i < R_i \leq N
  • (Li,Ri)(Lj,Rj)(L_i,R_i) \neq (L_j,R_j) (iji \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

L1L_1 R1R_1

L2L_2 R2R_2

\vdots

LML_M RMR_M

Output

Print the answer.

3 2
1 2
1 3
4

For example, for p=(2,1,3)p=(2,1,3), we will have x=(1,3)x=(1,3).

The four sequences that meet the requirement are x=(1,1),(1,3),(2,2),(2,3)x=(1,1),(1,3),(2,2),(2,3).

6 3
1 2
3 4
5 6
8
10 10
8 10
5 8
5 7
2 5
1 7
4 5
5 9
2 8
7 8
3 9
1060