require "byebug"

a = gets.split(" ")
$n = a[0].to_i
$k = a[1].to_i

$f = [1]
$prefix_f = [1]

$l = []
$r = []

$k.times do 
  a = gets.split(" ")
  ll = a[0].to_i
  rr = a[1].to_i
  $l.push(ll)
  $r.push(rr)
end

def sum_from(ll, rr) 
  if rr < 0
    0
  else
    ret = $prefix_f[rr]
    if ll > 0 
      ret -= $prefix_f[ll - 1]
    end
    ret
  end
end 

$mod = 998244353

$n.times do |i|
  ff = 0
  $k.times do |j|
    ff = (ff + sum_from(i + 1 - $r[j], i + 1 - $l[j])) % $mod
  end
  # byebug
  $f.push(ff)
  # p ff
  $prefix_f.push($prefix_f[i] + ff)
end

# p $f[4]
puts $f[$n - 1]