require 'set'

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

set=Set.new()
k.times do |i|
  lr[i][0].upto(lr[i][1]) do |j|
    set<<j
  end
end

dp=Array.new(n+1, 0)
dp[1]=1
2.upto(n) do |i|
  set.each do |j|
    next if i-j<=0
    dp[i]+=dp[i-j]
  end
end

puts dp[n]%998244353
