package main

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

func main() {
	n, k := readI(), readI()
	l, r := make([]int, k), make([]int, k)
	for i := 0; i < k; i++ {
		l[i], r[i] = readI(), readI()
	}
	sort.Ints(l)
	sort.Ints(r)
	p := make([]int, 0, n)
	for i := 0; i < k; i++ {
		for j := l[i]; j <= r[i]; j++ {
			p = append(p, j)
		}
	}

	pass := make(map[int]int)
	for i := n - 1; i > 0; i-- {
		a := 0
		for j := 0; j < len(p); j++ {
			cp := i + p[j]
			if cp > n {
				break
			} else if cp == n {
				a = mod.add(a, 1)
				continue
			}
			if v, ok := pass[cp]; ok {
				a = mod.add(a, v)
			}
		}
		pass[i] = a
	}
	fmt.Println(pass[1])
}

var mod = newModInt(998244353)

// Modular arithmetic utils
type modInt struct {
	modNum int
}

func newModInt(mod int) *modInt {
	m := modInt{modNum: mod}
	return &m
}

func (m modInt) mod(a int) int {
	a %= m.modNum
	if a < 0 {
		return a + m.modNum
	}
	return a
}

func (m modInt) pow(base, exponent int) int {
	res := 1
	for exponent > 0 {
		if exponent&1 == 1 {
			res = m.mod(res * base)
		}
		base = m.mod(base * base)
		exponent >>= 1
	}
	return res
}

func (m modInt) inv(a int) int {
	return m.pow(a, m.modNum-2)
}

func (m modInt) add(a, b int) int {
	return m.mod(a + b)
}

func (m modInt) sub(a, b int) int {
	return m.mod(a - b)
}

func (m modInt) mul(a, b int) int {
	return m.mod(a * b)
}

func (m modInt) div(a, b int) int {
	return m.mul(a, m.inv(b))
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-4.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}
