100 #ABC179D. [ABC179D] Leaping Tak

[ABC179D] Leaping Tak

Score : 400400 points

Problem Statement

There are NN cells arranged in a row, numbered 1,2,,N1, 2, \ldots, N from left to right.

Tak lives in these cells and is currently on Cell 11. He is trying to reach Cell NN by using the procedure described below.

You are given an integer KK that is less than or equal to 1010, and KK non-intersecting segments [L1,R1],[L2,R2],,[LK,RK][L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let SS be the union of these KK segments. Here, the segment [l,r][l, r] denotes the set consisting of all integers ii that satisfy lirl \leq i \leq r.

  • When you are on Cell ii, pick an integer dd from SS and move to Cell i+di + d. You cannot move out of the cells.

To help Tak, find the number of ways to go to Cell NN, modulo 998244353998244353.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1Kmin(N,10)1 \leq K \leq \min(N, 10)
  • 1LiRiN1 \leq L_i \leq R_i \leq N
  • [Li,Ri][L_i, R_i] and [Lj,Rj][L_j, R_j] do not intersect (iji \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

L1L_1 R1R_1

L2L_2 R2R_2

::

LKL_K RKR_K

Output

Print the number of ways for Tak to go from Cell 11 to Cell NN, modulo 998244353998244353.

5 2
1 1
3 4
4

The set SS is the union of the segment [1,1][1, 1] and the segment [3,4][3, 4], therefore S={1,3,4}S = \{ 1, 3, 4 \} holds.

There are 44 possible ways to get to Cell 55:

  • 123451 \to 2 \to 3 \to 4 \to 5,
  • 1251 \to 2 \to 5,
  • 1451 \to 4 \to 5 and
  • 151 \to 5.
5 2
3 3
5 5
0

Because S={3,5}S = \{ 3, 5 \} holds, you cannot reach to Cell 55. Print 00.

5 1
1 2
5
60 3
5 8
1 3
10 15
221823067

Note that you have to print the answer modulo 998244353998244353.