use std::collections::HashSet;
// d
fn main() {
    input! {
        n: usize,
        k: usize,
        lr: [(usize, usize); k]
    }

    let MOD = 998244353;

    let mut n_set: HashSet<usize> = HashSet::new();
    for i in lr {
        let l = i.0;
        let r = i.1;
        for j in l..r + 1 {
            n_set.insert(j);
        }
    }
    let mut n_vec: Vec<usize> = n_set.into_iter().map(|a| a).collect();
    n_vec.sort();
    let mut dp = vec![0; n];
    dp[0] = 1;
    for i in 0..n {
        for j in &n_vec {
            if i + j < n {
                dp[i + j] += dp[i];
                dp[i + j] %= MOD;
            }
        }
    }
    println!("{}", dp[n - 1]);
}

#[macro_export(local_inner_maccros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[macro_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
