use proconio::input;

#[allow(non_snake_case)]
fn main() {
    const MOD: i32 = 998244353;
    input!{
        N: usize,
        K: usize,
        LR: [(usize, usize); K]
    }
    let mut dp = vec![0; N];
    let mut a = vec![0; N];
    for (l, r) in LR.iter() {
        if *l < N {
        a[*l] = 1;
        }
        if r + 1 < N {
        a[r+1] = -1;
        }
    }
    for i in 1..N {
        for (l, r) in LR.iter() {
            dp[i] = (dp[i-1] + a[i]) % MOD;
            if i + l < N {
            a[i+l] += dp[i];
            a[i+l] %= MOD;
            }
            if i + r + 1 < N {
            a[i+r+1] -= dp[i];
            a[i+r+1] %= MOD;
            }
        }
    }
    let mut ans = dp[N-1];
    if ans < 0 {
        ans += MOD;
    }
    println!("{}", ans);
}
