N, K = gets.split.map(&:to_i)
DIV = 998244353
s = []
K.times do
  l, m = gets.split.map(&:to_i)
  s.concat((l..m).to_a)
end
count = Array.new(N, 0)

(1..N - 1).each do |i|
  (1..i - 1).each do |j|
    if s.include? i - j
      count[i] += count[j]
      if count[i] > DIV
        count[i] -= DIV
      end
    end
  end
  if s.include? i
    count[i] += 1
    if count[i] > DIV
      count[i] -= DIV
    end
  end
end
puts count.last