N, K = gets.split.map(&:to_i)
DIV = 998244353
s = []
K.times do
  s << gets.split.map(&:to_i)
end
dpsum = Array.new(N + 1, 0)
dpsum[1] = 1
dp = nil
(2..N).each do |i|
  dp = 0
  s.each do |s_i|
    l, r = s_i
    i_l = i - r
    i_l = 1 if i_l < 1
    i_r = i - l
    next if i_r < 1
    dp += dpsum[i_r] - dpsum[i_l - 1]
    dp = dp % DIV
  end
  dpsum[i] = dpsum[i - 1] + dp
  dpsum[i] = dpsum[i] % DIV
end
puts dp