N, K = gets.chomp.split.map(&:to_i)
MOD = 998244353

LRs = []
K.times do
    LRs << gets.chomp.split.map(&:to_i)
end

dp = Array.new(N+1, 0)
dp[0] = 1
dp[1] = -1

N.times do |i|
    if i > 0 then
        dp[i] += dp[i-1]
        dp[i] %= MOD 
    end
    LRs.each do |l, r|
        if i+l < N then
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        end
        if i+r+1 < N then
            dp[i+r+1] -= dp[i]
            dp[i+r+1] %= MOD
        end
    end
end

puts dp[N-1]