#!/usr/bin/env ruby

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

LR = []

K.times do |i|
  LR[i] = gets.chomp.split.map(&:to_i)
end

LR.sort_by!(&:first)

ds = [0, 1]

2.upto(N) do |i|
  dpi = 0

  LR.each do |(l, r)|
    right = i - l
    break if right < 0

    left = i - r - 1
    left = 0 if left < 0

    dpi += ds[right] - ds[left]
  end

  ds[i] = (dpi + ds[i-1]) % 998244353
end

puts (ds[N] - ds[N-1]) % 998244353
