MOD = 998244353
n,k = gets.chomp.split(" ").map(&:to_i)
l,r = k.times.map{gets.split.map(&:to_i)}.transpose
arr = []
k.times do |i|
  for i in l[i]..r[i]
    arr << i
  end
end
arr = arr.sort.reverse
dp = Array.new(n+1,0)
dp[n] = 1
n.downto(2) do |i|
  next if arr.empty?
  while i - arr[0] < 1
    arr.shift
    break if arr.empty?
  end
  arr.each do |x|
    dp[i-x] = (dp[i] + dp[i-x]) % MOD
  end
end
puts dp[1]