package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var N, K int
	fmt.Fscan(reader, &N, &K)

	S := make([]int, 0)
	for i := 0; i < K; i++ {
		var l, r int
		fmt.Fscan(reader, &l, &r)
		for j := l; j <= r; j++ {
			S = append(S, j)
		}
	}
	fmt.Println(S)
	dp := make([]int, N)
	mod := 998244353
	dp[0] = 1
	for n := 0; n < N; n++ {
		for _, i := range S {
			if n >= i {
				dp[n] += dp[n-i]
			}
		}
	}
	ans := dp[N-1] % mod
	fmt.Println(ans)

}
