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

MOD = 998244353

step = [0]*N
step[0]=1

N.times do |i|
    next if i!=0 && step[i]==0
    s = step[i]
    LRs.each do |l,r|
        (l..r).each do |j|
            t = i+j
            break if t >= N
            step[t] = (step[t] + s) % MOD
        end
    end
end

p step[-1]