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

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