package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)

	n, k := nextInt(), nextInt()

	ls := make([]int, k+1)
	rs := make([]int, k+1)

	for i := 1; i <= k; i++ {
		ls[i], rs[i] = nextInt(), nextInt()
	}

	sort.Slice(rgs, func(i, j int) bool {
		return rgs[i] < rgs[j]
	})

	mod := 998244353

	dp := make([]int, n+1)
	dp[1] = 1
	for i := 1; i <= n; i++ {
		for j := 1; j <= k; j++ {
			for rg := ls[j]; rg <= rs[i]; rg++ {
				if i+rg > n {
					break
				}
				dp[i+rg] += (dp[i] % mod)
			}
		}
	}
	fmt.Println(dp[n] % mod)
}
