use proconio::{fastout, input};
const MOD: usize = 998244353;
#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        lr: [(usize,usize); k]
    }
    let mut lr: Vec<(usize, usize)> = lr;

    let mut dp = vec![0; n];
    dp[0] = 1;
    for i in 1usize..n {
        'sub: for j in lr.iter() {
            for k in j.0..=j.1 {
                if i < k {
                    continue 'sub;
                }
                dp[i] += dp[i - k];
                dp[i] %= MOD;
            }
        }
    }
    println!("{}", dp[n - 1]);
}
