use proconio::input;

fn main() {
    input!{
        n: usize,
        k: usize,
        lr: [[usize; 2]; k],
    }
    let mut s = Vec::new();
    for i in 0..k {
        for j in lr[i][0]..lr[i][1]+1 {
            s.push(j);
        }
    }
//    s.sort();
    let mut dp = vec![0; n+1];
    for i in &s {
        dp[*i] = 1;
    }
    for i in 0..n {
        for j in &s {
            if i + *j <= n {
                dp[i+*j] += dp[i];
                dp[i+*j] %= 998244353;
            }
        }
    }
    println!("{}", dp[n-1]);
}
