n, k = gets.strip.split.map(&:to_i)
s = []
MOD = 998244353
k.times do
  _l, _r = gets.strip.split.map(&:to_i)
  s = s | (_l.._r).to_a
end
s = s.uniq
s.sort!

dp = Array.new(n + 1, 0)
dp[1] = 1
(2..n).each do |i|
  s.each do |_s|
    dp[i] += dp[i - _s] if i - _s > 0 && dp[i - _s] > 0
  end
end

puts dp[n] % MOD
