use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.input()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    const MOD: usize = 998244353;
    let n: usize = sc.input();
    let k: usize = sc.input();
    let mut sections = vec![];
    for _ in 0..k {
        let l: usize = sc.input();
        let r: usize = sc.input();
        sections.push((l, r));
    }


    let mut dp = vec![0; n * 2 + 1];
    dp[0] = 1;
    dp[1] = 1;
    for i in 1..n {
        for (l, r) in &sections {
            if i + *l > n {
                continue;
            }
            for d in *l..=*r {
                if i + d > n {
                    break;
                }
                dp[i + d] += dp[i] % MOD;
                dp[i + d] %= MOD;
            }
        }
    }
    println!("{}", dp[n]);
}
