N, K = gets.split.map(&:to_i)
mod = 998244353
dp = Array.new(n, 0)
dp[0] = 1
lr = k.times.map {gets.split.map(&:to_i)}

n.times do |i|
  dp[i + 1] += dp[i] if 0 < i && i + 1 < N
  lr.each do |l, r|
    dp[i + l] = (dp[i + l] + dp[i]) % m if i + l < N
    dp[i + r + 1] = (dp[i + r + 1] - dp[i]) if i + r + 1 < N
  end
end

puts dp[-1] % mod