#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        n: usize,
        k: usize,
        lr: [(usize,usize);k]
    }
    let mut dp = vec![0; n];
    let mut s = vec![];
    for (l, r) in lr {
        for x in l..=r {
            s.push(x);
        }
    }
    dp[0] = 1;
    for i in 0..n {
        for x in s.iter() {
            if x + i < n {
                dp[x + i] += dp[i] % 998244353;
                dp[x + i] %= 998244353;
            }
        }
    }
    println!("{}", dp[n - 1]);
}
