use proconio::{input, fastout};

#[fastout]
fn main() {
    const MODNUM: i64 = 998244353;
    input!{
        n: usize,
        k: usize,
        lr:[(i64, i64); k]
    }
    // d[n] = 0 ~ n までいく通り数
    // kubarudp: d[i + d] += f[i]  all d in S
    let mut dp = vec![0; n+1];
    let mut dpsum = vec![0; n + 1];

    // a[i] = f[i] - f[i-1]

    dp[1] = 1;
    dpsum[1] = 1;
    for i in 2..=n {
        for j in 0..k {
            let (l, r) = lr[j];
            let li = (i as i64 - r).max(1);
            let ri = i as i64 - l;
            if li > 0 {
                dp[i] -= dpsum[(li - 1) as usize];
            }
            if ri >= 0 {
                dp[i] += dpsum[ri as usize];
            }

        }
        dpsum[i] = dpsum[i-1] + dp[i];
    }

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