Devisor = 998244353
N, K = gets.chomp.split(' ').map(&:to_i)
sections = Array.new(K){ gets.chomp.split(' ').map(&:to_i) }

#### 素朴なもらうDP。やはりTLEする。
# dp = Array.new(N + 1) { 0 }
# dp[1] = 1
# 2.upto(N) do |i|
#     sections.each do |section|
#         s, e = section
#         s.upto(e) do |j|
#             dp[i] += dp[i - j] if i - j >= 1
#         end
#     end
# end
# puts dp[N] % Devisor

#### もらうDPに累積和も盛り込む。
dp = Array.new(N + 1) { 0 }
dp[1] = 1
cum = Array.new(N + 1) { 0 }
cum[1] = 1
2.upto(N) do |i|
    sections.each do |section|
        s, e = section
        cs = [i - e - 1, 0].max
        ce = [i - s, 0].max
        dp[i] += cum[ce] - cum[cs]
        # puts "i = #{i}, section = #{section.to_s}"
        # puts "dp : #{dp.to_s}"
    end
    cum[i] = cum[i - 1] + dp[i]
    # puts "cum : #{cum.to_s}"
end
puts dp[N] % Devisor