use proconio::{input, fastout};

#[fastout]
fn main() {
    const MODNUM: i64 = 998244353;
    input!{
        n: usize,
        k: usize,
        lr:[(i64, i64); k]
    }
    let mut flg = vec![false; n + 1];
    for &(l, r) in &lr {
        for i in l..=r {
            flg[i as usize] = true;
        }
    }
    // d[n] = 0 ~ n までいく通り数
    // ans = d[n-1]
    // d[i] = sigma[d[k]] (0 ~ i-1 if k in lr)
    let mut d = vec![0; n+1];
    d[0] = 0;
    for i in 0..=n {
        if flg[i] {
            d[i] = 1;
        }
    }
    for i in 0..n {
        for dlt in 1..i {
            if flg[dlt] {
                d[i] += d[i - dlt];
            }
        }
    }

    let ans = d[n-1] % MODNUM;
    println!("{}", ans);
}
