import * as fs from 'fs';
// main
function main(input: string[]) {
    // param
    let n, k;
    let lk, rk;
    let ans;
    // init
    [n, k] = input.shift().split(" ").map(x => Number(x));
    lk = new Array(k);
    rk = new Array(k);
    for (let kx = 0; kx < k; kx++) {
        [lk[kx], rk[kx]] = input[kx].split(" ").map(x => Number(x));
    }
    // solve
    let lr = new Array(n + 1).fill(0);
    for (let kx = 0; kx < k; kx++) {
        for (let lrx = lk[kx]; lrx <= rk[kx]; lrx++) {
            lr[lrx] = lrx;
        }
    }
    let mn = new Array(n + 1).fill(0);
    mn[1] = 1;
    for (let nx = 2; nx <= n; nx++) {
        for (let lrx = 1; lrx <= n; lrx++) {
            if (0 < lr[lrx] && 1 <= nx - lrx) {
                mn[nx] = (mn[nx] + mn[nx - lrx]) % 998244353;
            }
        }
    }
    ans = mn[n];
    // answer
    console.log(ans);
}
// entrypoint
function entrypoint() {
    try {
        // linux
        let input = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        console.debug = function () { };
        main(input);
    }
    catch (ex) {
        // windows
        const lines: string[] = [];
        // @ts-ignore
        const reader = require('readline').createInterface({
            // @ts-ignore
            input: process.stdin,
            // @ts-ignore
            output: process.stdout
        });
        reader.on('line', function (line: string) {
            lines.push(line);
        });
        reader.on('close', function () {
            let input = lines;
            main(input);
        });
    }
}
entrypoint();
