require "set"
n,k = gets.chomp.split(" ").map(&:to_i)

MOD = 998244353

set = Set.new
k.times.each do 
  l, r = gets.chomp.split(" ").map(&:to_i)
  (l..r).each do |i|
    set << i
  end
end
arr = set.to_a.sort_by{|a| a}

dp = Array.new(n, 0)
dp << 0
dp[1] = 1

(1..n).each do |i|
  arr.each do |s|
    x = i - s
    break if x <= 0
    dp[i] += dp[x]
    dp[i] %= MOD
  end
end

puts dp[-1]
 