MOD = 998244353

n, k = $stdin.readline.chomp.split.map(&:to_i)

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

k.times do
  l, r = $stdin.readline.chomp.split.map(&:to_i)
  cnt[l - 1] += 1
  cnt[r] -= 1
end

s = []
s << 1 if cnt[0] != 0
n.times do |i|
  cnt[i + 1] += cnt[i]
  s << i + 2 if cnt[i + 1] != 0
end

n.times do |i|
  next if dp[i] == 0

  s.each do |x|
    next if i + x >= n

    dp[i + x] = (dp[i + x] + dp[i]) % MOD
  end
end
puts dp[n - 1]