n,k = gets.split.map &:to_i

MOD = 998244353

step = []

p = Array.new(n, 0)
p[0] = 1
p[1] = 0

k.times{
	l,r = gets.split.map &:to_i
	step << [l,r+1]
	
	if l == 1 then
		p[1] = 1
	end
}

(2...n).each{ |x|
	p[x] = p[x-1]
	step.each{ |l,r|
		if x - r >= 0 then
			p[x] = (p[x] - p[x - r]) % MOD
		end
		if x - l >= 0 then
			p[x] = (p[x] + p[x - l]) % MOD
		end
	}
}

puts p[n-1]