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

MOD = 998244353

step = []

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

k.times{
	l,r = gets.split.map &:to_i
	step += (l..r).to_a
}

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

puts p[n-1]