Dishonest Paths

Time limit: 1s Memory limit: 256MB Input: Output:

You are given an integer NN and the following undirected graph:

  • The graph contains NN nodes, which are numbered from 11 to NN.
  • There exists an undirected edge between two nodes UU and VV (1U,VN1 \le U,V \le N) if and only if 1UV21 \le |U-V| \le 2.

There are MM distinct forbidden edges (Ui,Vi)(U_i,V_i) (i=0,,M1i = 0, \ldots, M - 1).

Task

Find the number of simple paths in this graph from node 11 to node NN that do not contain any of the MM forbidden edges. Since the answer can be very large, print its remainder modulo 998 244 353998 \ 244 \ 353.

A simple path is a sequence of \textbf{pairwise distinct} nodes u1,u2,,uku_1,u_2,\ldots,u_k such that uiu_i and ui+1u_{i+1} are connected by an edge in the graph, for all 1i<k1 \le i < k.

Input data

The first line of input contains two integers NN and MM -- the number of nodes in the graph, and the number of forbidden edges, respectively.

Each of the next MM lines of input contains two integers UiU_i and ViV_i -- the endpoints of the forbidden edges.

Output data

Print the number of simple paths (modulo 998 244 353998 \ 244 \ 353) from node 11 to node NN that do not contain any of the MM forbidden edges.

Constraints and clarifications

  • 3N10183 \le N \le 10^{18}.
  • 0Mmin(2N3,100 000)0 \le M \le \min(2 \cdot N - 3, 100 \ 000).
  • 1Ui<ViN1 \le U_i < V_i \le N, 1ViUi21 \le V_i - U_i \le 2 for each i=0M1i=0\ldots M-1.
  • The edges (Ui,Vi)(U_i, V_i) are pairwise distinct.
# Score Constraints
1 0 Examples
2 15 N1 000 000N \le 1 \ 000 \ 000, M=0M=0
3 15 M=0M = 0
4 20 N20N \le 20
5 20 N1 000 000N \le 1 \ 000 \ 000
6 30 No additional restrictions

Example 1

stdin

5 0

stdout

7

Explanation

In the first sample case, there are 77 simple paths from node 11 to node 55:

  • 124351 \rightarrow 2 \rightarrow 4 \rightarrow 3 \rightarrow 5
  • 12451 \rightarrow 2 \rightarrow 4 \rightarrow 5
  • 123451 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 5
  • 12351 \rightarrow 2 \rightarrow 3 \rightarrow 5
  • 132451 \rightarrow 3 \rightarrow 2 \rightarrow 4 \rightarrow 5
  • 1351 \rightarrow 3 \rightarrow 5
  • 13451 \rightarrow 3 \rightarrow 4 \rightarrow 5

Example 2

stdin

5 1
3 4

stdout

4

Explanation

In the second sample case, there are 44 simple paths from node 11 to node 55 that do not contain the edge (3,4)(3,4):

  • 12451 \rightarrow 2 \rightarrow 4 \rightarrow 5
  • 12351 \rightarrow 2 \rightarrow 3 \rightarrow 5
  • 132451 \rightarrow 3 \rightarrow 2 \rightarrow 4 \rightarrow 5
  • 1351 \rightarrow 3 \rightarrow 5

Example 3

stdin

3 2
1 2
1 3

stdout

0

Explanation

In the third sample case, there are no simple paths from node 11 to node 33 that do not contain the edges (1,2)(1,2) and (1,3)(1,3).

Example 4

stdin

8 6
4 5
6 7
6 8
1 2
2 3
2 4

stdout

2

Explanation

In the fourth sample case, there are only two valid simple paths from node 11 to node 88:

  • 1346581 \rightarrow 3 \rightarrow 4 \rightarrow 6 \rightarrow 5 \rightarrow 8
  • 135781 \rightarrow 3 \rightarrow 5 \rightarrow 7 \rightarrow 8

Example 5

stdin

100 8
1 2
98 100
54 55
20 22
80 81
80 82
83 84
82 84

stdout

249047307

Example 6

stdin

2000000000 0

stdout

548668789

Log in or sign up to be able to send submissions!