n, k = gets.split(' ').map(&:to_i)
ranges = k.times.map { gets.split(' ').map(&:to_i) }

m = 998244353

fs = [1]
cum = [1]
(1...n).each do |i|
  f = 0
  ranges.each do |r|
    f += cum[i - r[0]] if i - r[0] >= 0
    f -= cum[i - (r[1] + 1)] if i - (r[1] + 1) >= 0
    f %= m
  end
  fs << f
  cum << ((cum.last || 0) + f) % m
end

puts fs.last
