M = 998_244_353
n, k = gets.chomp.split(' ').map(&:to_i)
lr = k.times.map { gets.chomp.split(' ').map(&:to_i) }.sort_by

dp = (0..n).map { 0 }
dp[1] = 1

(2..n).each do |i|
  temp = lr.map { |l, r| dp[[0, i - l].max] - dp[[0, i - r - 1].max] }.sum
  dp[i] = (dp[i - 1] + temp) % M
end

puts dp[n] - dp[n - 1]
