#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

const INF: usize = 99999999999999;
const MOD: usize = 998244353;

fn proc_r(n: usize, pos: usize, ca: &mut [usize], set: &Vec<usize>, num: usize ) -> usize {
	if pos == n {
		return 1;
	}
	if ca[pos] != INF {
		return num * ca[pos] % MOD;
	}
	let mut sum = 0;
	for i in 0..set.len() {
		if pos+set[i] > n {
			continue;
		}
		sum += proc_r(n, pos+set[i], ca, set, num);
	}
	ca[pos] = sum % MOD;
	return num * ca[pos] % MOD;
}

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

	let mut set: Vec<usize> = vec![];
	for i in 0..k {
		for j in lr[i].0..=lr[i].1 {
			set.push(j);
		}
	}
	//set.sort();
	set.sort_by_key(|&x| std::cmp::Reverse(x));
	let mut ca = vec![INF; n];
	let ans = proc_r(n-1, 1-1, &mut ca, &set, 1);

	println!("{}", ans);
}
