N,K = gets.split.map(&:to_i)
LR = K.times.map{ gets.split.map(&:to_i) }

D = [0]*N
D[0] = 1
(0..N-2).each{|i|
	next if D[i] == 0
	LR.each{|l,r|
		(l..[r,N-1-i].min).each{|d|
			D[i+d] = (D[i+d] + D[i]) % 998244353
		}
	}
}
p D[-1]
