n, k = gets.split.map(&:to_i)
m = 998244353
lr = k.times.map {gets.split.map(&:to_i)}.sort_by{|e| e[0]}

dp = Array.new(n, 0)
dp[0] = 1
n.times do |i|
    lr.each do |l, r|
        l.upto(r) do |j|
            c += 1
            break if i + j >= n
            dp[i+j] = (dp[i] + dp[i+j]) % m
        end or break
    end
end

p dp[-1]