fn main() {
    proconio::input! {
        n: usize,
        k: usize,
        mut lrs: [(usize, usize); k],
    }
    lrs.sort();
    const M: usize = 998244353;
    let n = n;
    let mut dp = vec![0usize; n + 2];
    dp[0] = 1;
    for d in 0..=n {
        for (l, r) in &lrs {
            for i in d + l..=d + r {
                if i < dp.len() {
                    dp[i] += dp[d];
                    dp[i] %= M;
                }
            }
        }
    }
    println!("{}", dp[n - 1]);
}
