#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code,
  unused_macros
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
//use std::collections::HashSet;
use petgraph::unionfind::UnionFind;
use std::cmp::*;
use std::collections::*;
macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}
const MOD: usize = 998244353;
fn main() {
  input! {
     N:usize, K:usize,
     LR:[(usize,usize);K]
  }
  // マス n に到達できる場合の数を dp[n]で求める。
  let mut dp = vec![0; N + 1];
  let mut LR = LR;
  LR.sort();
  dp[1] = 1;
  let mut mini = 0;
  //while mini < N {
  //  mini += LR[0].0;
  for m in 1..N {
    for i in 0..LR.len() {
      let l = LR[i].0;
      let r = LR[i].1;
      if dp[m] > 0 {
        for n in l..=min(r, N - m) {
          dp[n + m] += dp[m];
          dp[n + m] %= MOD;
        }
      }
      //debug!(m, i, dp);
    }
    //    dp[m] = dp[m] % MOD;
  }
  //}
  println!("{}", dp[N]);
}
