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

n.times do |i|
  cnt[i + 1] += cnt[i]
end

n.times do |i|
  n.times do |j|
    next if cnt[j] == 0
    next if j + i + 1 >= n

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