MAX = 998244353
N, K = gets.split.map(&:to_i)
aa = []
K.times do
  l, r = gets.split.map(&:to_i)
  aa += (l..r).to_a
end

b = aa
# pp b

ANS = Array.new(N * 2, 0)
ANS[0] = 1
N.times do |i|
  a = ANS[i]
  b.each do |v|
    ANS[i + v] = (ANS[i + v] + a) % MAX
  end
end

puts ANS[N - 1]
