require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=998244353
n,k = gets.chomp.split.map(&:to_i)
ls = []
rs = []
k.times do
  ll, rr = gets.chomp.split.map(&:to_i)
  ls.push ll
  rs.push rr
end

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

2.upto(n) do |i|
  count = 0
  k.times do |j|
    l = i - rs[j]
    r = i - ls[j]
    if r >= 1
      kukan_sum[j] += dp[r]
    end
    if l >= 2
      kukan_sum[j] -= dp[l-1]
    end
    kukan_sum[j] = (kukan_sum[j] + MOD) % MOD
    count += kukan_sum[j]
  end
  dp[i] = count % MOD
end

# p dp

puts dp.last
