N,k=gets.split.map(&:to_i)
l=[]
k.times { l << gets.split.map(&:to_i)}
dp=Array.new(N+1){0}
dp[1]=1
sum=[0,1]
(2..N).each do |i|
  div=0
  l.each do |a,b|
    aa= i-b-1>0 ?sum[i-b-1]:0
    bb= i-a>0 ?sum[i-a]:0
    div=bb-aa
    dp[i]+=div
  end
  sum[i]=sum[i-1]+dp[i]
end
p dp[N]%998244353
