MOD = 998244353
n,k = gets.chomp.split(" ").map(&:to_i)
l,r = k.times.map{gets.split.map(&:to_i)}.transpose
dp = Array.new(n+1,0)
dp[n] = 1
arr = Array.new(n+1,0)
arr[n] = 1
arr[n-1] = -1
n.downto(1) do |i|
  if i+1 <= n
    arr[i] += arr[i+1]
    arr[i] %= MOD
  end
  k.times do |j|
    arr[i-l[j]] += arr[i] if i-l[j] > 0
    arr[i-r[j]-1] -= arr[i] if i-r[j]-1 > 0
  end
end
puts arr[1]