require 'set'

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

dp=Array.new(n+1, 0)
dp[1]=1
n.times do |i|
  k.times do |j|
    lr[j][0].upto(lr[j][1]) do |k|
      dp[i+k]+=dp[i] if i+k<=n
    end
  end
end

puts dp[n]%998244353
