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|
    a=lr[j][0]
    b=lr[j][1]+1
    dp[i+a]+=dp[i]%998244353 if i+a<n
    dp[i+b]-=dp[i]%998244353 if i+b<n
  end
end

puts dp[n-1]%998244353
