use proconio::{fastout, input};
const MOD: usize = 998244353;
#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize
    }
    let mut set: Vec<usize> = vec![];
    for _ in 0..k {
        input! {
            l: usize,
            r: usize
        }
        for i in l..=r {
            set.push(i);
        }
    }

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