use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

const MOD: i64 = 998244353;

fn main() {
    input! {
        n:usize,
        k:usize,
        lr: [(usize, usize); k],
    }

    let mut dp = vec![0; n + 1];
    let mut a = vec![1];
    dp[0] = 1;
    let mut sum = 1;

    for i in 1..n {
        let mut next = 0;
        for j in 0..lr.len() {
            let l = lr[j].0;
            let r = lr[j].1;
            if l > a.len() {
                continue;
            }
            next += a[a.len() - l];
            if r + 1 > a.len() {
                continue;
            }
            next -= a[a.len() - r - 1];
            next %= MOD;
        }
        dp[i] = next;
        sum += next;
        a.push(sum);
        // println!("dp:{:?}", dp);
        // println!("a:{:?}", a);
    }
    println!("{}", dp[n - 1]);
}
