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

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