function main()
  n,k=parse.(Int,split(readline()))
  l=Int[]
  dp=zeros(Int,n)
  dp[1]=1
  for i=1:k
    a,b=parse.(Int,split(readline()))
    for j=a:b
      push!(l,j)
    end
  end
  now=1
  while now!=n
    Now=dp[now]
    for i=l
      if now+i<=n
        dp[now+i]=mod(dp[now+i]+Now,998244353)
      end
    end
    now+=1
  end
  println(mod(dp[n],998244353))
end
main()