n, k = gets.chomp.split(' ').map(&:to_i)
ranges = []
k.times { ranges << gets.chomp.split(' ').map { |i| i.to_i - 1 } }

dp = Array.new(n + 1, 0)
dp[1] = 1

(1...n).each do |i|
  sum = 0
  ranges.each do |l, r|
    rr, ll = i - l, i - r
    next if rr < 1
    ll = 1 if ll < 0
    sum += dp[rr] - dp[ll - 1]
  end
  dp[i + 1] = (dp[i] + sum) % 998244353
end
print dp[n] - dp[n - 1]
