#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashSet;
// use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        K: usize,
        LRs: [(usize, usize); K],
    }

    const MOD: i64 = 998244353;

    let mut dp = vec![0i64; N];
    dp[0] = 1;

    let mut choises: HashSet<usize> = HashSet::new();

    for &(l, r) in LRs.iter() {
        for i in l..=r {
            choises.insert(i);
        }
    }

    // for &c in choises.iter() {
    //     dbg!(c);
    // }

    let choises_vec: Vec<usize> = choises.into_iter().collect();

    for n in 1..N {
        let mut cand: i64 = 0;

        for &c in choises_vec.iter() {
            if c <= n {
                cand = (cand + dp[n - c]) % MOD;
            }
        }

        dp[n] = cand;
    }

    let ans = dp[N - 1];
    println!("{}", ans);
}
