MOD = 998244353
io = DATA.eof? ? STDIN : DATA
n,k=io.gets.split.map(&:to_i)
dp=Array.new(n+1,0)
dp[1]=1
cand=k.times.flat_map do
  l,r=io.gets.split.map(&:to_i)
  (l..r).to_a
end
(1..n).each do |i|
  cand.each do |c|
    next if i+c>n
    dp[i+c]+=dp[i]
    dp[i+c]%=MOD
  end
end
puts dp[n]
__END__
