N, K = gets.split.map(&:to_i)
s = []
K.times do
  l, r = gets.split.map(&:to_i)
  s << (l..r).to_a
end
s.flatten!
d = Array.new(N, 0)
d[0] = 1
(N-1).times do |i|
  s.each do |j|
    d[i + j] += d[i] if i + j < N
  end
end
puts d.last % 998244353
