#![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;

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

        for &(l, r) in LRs.iter() {
            if n < l {
                continue;
            }

            for i in l..=r {
                if i <= n {
                    cand = (cand + dp[n - i]) % MOD;
                }
            }
        }

        dp[n] = cand;
    }

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