N,K = gets.split.map &:to_i
LRs = K.times.map{ gets.split.map(&:to_i) }

MOD = 998244353

c = 0
event = [0]*N
event[0] = 1
event[1] = -1

N.times do |i|
    c += event[i]
    c %= MOD
    next if c == 0
    LRs.each do |l,r|
        event[i+l] += c if i+l < N
        event[i+r+1] -= c if i+r+1 < N
    end
end

p c % MOD