#![allow(non_snake_case)]

use proconio::input;
use proconio::fastout;
use std::cmp::min;

#[fastout]
fn main() {
    const M: i32 = 998244353;
    input! {
        N: usize,
        K: usize,
        LR: [(usize, usize); K],
    }
    let mut dp = vec![0; N + 1];
    dp[0] = 1;
    dp[1] = M - 1;
    let mut x = 0;
    for i in 0..N {
        x = (x + dp[i]) % M;
        for &(L, R) in &LR {
            let l = min(i + L, N);
            let r = min(i + R + 1, N);
            dp[l] = (dp[l] + x) % M;
            dp[r] = (dp[r] + M - x) % M;
        }`
    }
    println!("{}", x);
}
