#!/usr/bin/env ruby

N, K = gets.chomp.split.map(&:to_i)

LR = []

K.times do |i|
  LR[i] = gets.chomp.split.map(&:to_i)
end

LR.sort_by!(&:first)

dp = [0, 1]
ds = [0, 1]
2.upto(N) do |i|
  dp[i] = 0
  LR.each do |(l, r)|
    break if i < l
    right = i - l
    left = i - r - 1
    left = 0 if left < 0
    dp[i] += ds[right] - ds[left]
  end

  ds[i] = dp[i] + ds[i-1]
end

puts dp[N] % 998244353
