MOD = 998244353

n, k = $stdin.readline.chomp.split.map(&:to_i)
rng = Array.new(k) { $stdin.readline.chomp.split.map(&:to_i) }

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

n.times do |i|
  if i == 0
    dp[i] = 1
  else
    k.times do |j|
      lj, rj = rng[j]
      l = [0, i - rj].max
      r = [0, i - lj + 1].max
      dp[i] = (dp[i] + sdp[r] - sdp[l]) % MOD
    end
  end
  sdp[i + 1] = (sdp[i] + dp[i]) % MOD
end
puts dp[n - 1]