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

D = [0]*N
d,D[0],D[1] = 0,1,-1
(0..N-1).each{|i|
	d = (d + D[i]) % M
	LR.each{|l,r|
		next unless i+l < N
		D[i+l] = (D[i+l] + d) % M
		next unless i+r+1 < N
		D[i+r+1] = (D[i+r+1] - d) % M
	}
}
p d
