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

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