package main

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

const mod int = 998244353

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()

	ws := make([]int, n+2)
	for i := 0; i < k; i++ {
		l, r := nextInt(), nextInt()
		ws[l]++
		ws[r+1]--
	}

	ns := make([]int, 0)
	for i := 1; i < len(ws); i++ {
		ws[i] += ws[i-1]
		if ws[i] > 0 {
			ns = append(ns, i)
		}
	}

	dp := make(map[int]int)
	var dfs func(s int) int
	dfs = func(s int) int {
		if v, ok := dp[s]; ok {
			return v
		}

		if s == n {
			return 1
		}
		if s > n {
			return 0
		}

		cnt := 0
		for i := 0; i < len(ns); i++ {
			cnt += dfs(s + ns[i])
			cnt %= 998244353
		}

		dp[s] = cnt
		return cnt
	}
	ans := dfs(1)

	fmt.Println(ans)
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
