const input = require("fs").readFileSync("/dev/stdin", "utf8")

const lines = input.split('\n')
const [N, K] = lines[0].split(' ').map(Number)

const s = []
for (let i = 1; i <= K; i++) {
    const [L, R] = lines[i].split(' ').map(Number)
    s.push(...Array(R - L + 1).fill().map((_, i) => i + L))
}

const map = Array(N).fill(0)
map[0] = 1
const mod = 998244353

for (let i = 1; i < map.length; i++) {
    let c = 0
    for (let j = 0; j < s.length; j++) {
        c += map[i - s[j]] || 0
    }
    map[i] = c % mod
}

console.log(map.pop())
