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

union = []
sectinos.each do |section|
    s, e = section
    s.upto(e) { |i| union.push(i) }
end

dp = Array.new(N + 1) { 0 }
dp[1] = 1
1.upto(N - 1) do |i|
    next if dp[i] == 0
    union.each do |u|
        dp[i + u] += dp[i] if i + u <= N
        # p dp
    end
end
puts dp[N] % Devisor