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

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

puts dp[n-1]%998244353
