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

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

puts dp[n-1]%998244353
