using DataStructures
function main()
  n,k=parse.(Int,split(readline()))
  lr=(x->parse.(Int,split(x))).(readlines())
  ft=FenwickTree{Int}(n)
  inc!(ft,1,1)
  for now=1:n-1
    for i=lr
      l=now+i[1]
      r=now+i[2]
      r < n && incdec!(ft,l,r+1,ft[now])
      r >= n && l<=n && inc!(ft,l,ft[now])
    end
  end
  println((prefixsum(ft,n)-prefixsum(ft,n-1))%998244353)
end
main()