package main

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


func main() {
	var n,k int
	fmt.Scan(&n, &k)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	mod := 998244353
	// l := make([]int, n)
	// r := make([]int, n)
	m := make(map[int]bool, n)
	for i := 0; i < k; i++ {
		sc.Scan()
		l, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		r, _ := strconv.Atoi(sc.Text())
		for j := l ; j <= r; j++ {
			m[j] = true
		}
	}
	dp := make([]int, n+1)
	dp[0] = 1

	for i := 1 ; i < n; i++{
		for k, v := range m {
			if i < k {
				continue
			}
			if v {
				dp[i] += dp[i-k]
			}
		}
		dp[i] %= mod
	}
	fmt.Println(dp[n-1])
}

