n,k = gets.split.map(&:to_i)
s = readlines.map{|line| line.split.map(&:to_i)}
MOD = 998244353
dp = Array.new(n,0)
wa = Array.new(n+1)
dp[0] = 1
wa[0] = 0
wa[1] = 1
for i in 1..(n-1)
  for j in 0..(k-1)
    if i-s[j][0] >= 0 && i-s[j][1] < 0
      dp[i] += wa[i-s[j][0]+1]%MOD
    elsif i-s[j][0] >= 0 && i-s[j][1] >= 0
      dp[i] += (wa[i-s[j][0]+1]-wa[i-s[j][1]])%MOD
    end
  end
  wa[i+1] = (wa[i]+dp[i])%MOD
end
puts dp[n-1]%MOD