use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
    };

    let mut v = vec![];

    for _ in 0..k {
        input! {
            l: usize,
            r: usize,
        }

        for i in l..=r {
            v.push(i);
        }
    }

    let mut dp: Vec<usize> = vec![0; n];
    dp[0] = 1;

    for i in 1..n {
        for j in v.iter() {
            if i >= *j {
                dp[i] += dp[i - j];
                dp[i] %= 998244353;
            }
        }
    }

    println!("{}", dp[n - 1]);
}
