package main

import (
	"fmt"
)

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

	s := make([]int, 0)
	for i := 0; i < k; i++ {
		fmt.Scan(&l, &r)
		if l == r {
			s = append(s, l)
		} else {
			s = append(s, l, r)
		}
	}

	dp := make([]int, n)
	dp[0] = 1
	for i := 0; i <= n; i++ {
		for _, v := range s {
			if i+v < n {
				dp[i+v] += dp[i]
			} else {
				break
			}
		}
	}
	fmt.Println(dp[n-1] % 998244353)
}
