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