N, K = gets.split.map(&:to_i)
L = []
R = []
K.times do
    l, r = gets.split.map(&:to_i)
    L << l
    R << r
end

MOD = 998244353

dp = [0] * N
sp = [0] * (N + 1)

dp[0] = 1

for i in 1 .. N - 1
    sp[i] = (sp[i - 1] + dp[i - 1]) % MOD
    for l, r in L.zip(R)
        dp[i] += sp[[0, i - l + 1].max] - sp[[0, i - r].max]
    end
    dp[i] %= MOD
end

puts dp[N - 1]