n,k=gets.split.map(&:to_i)
m=998244353
dp=[0,1]
l,r=[],[]
k.times do |i|
  ll,rr=gets.split.map(&:to_i)
  l << ll
  r << rr
end
s=[0]*10
2.upto(n) do |i|
  k.times do |j|
    if l[j]<=i-1
#      p [1,i,j]
      s[j]+=dp[i-l[j]]
      s[j]%=m
    end
    if r[j]<=i-2
#      p [2,i,j]
      s[j]-=dp[i-r[j]-1]
      s[j]%=m
    end
  end
  dp[i]=s.sum%m
end
puts dp[-1]
