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.sort
c = b.length
# pp b

ANS = Array.new(N * 2, 0)
ANS[0] = 1
N.times do |i|
  a = ANS[i]
  c.times do |j|
    tmp = i + b[j]
    if tmp > N
      c = j
      break
    end
    ANS[tmp] = (ANS[tmp] + a) % MAX
  end
end

puts ANS[N - 1]
