const MOD = 998244353

function solve()
    N, K = parse.(Int, split(readline()))
    S = []
    for _ = 1:K
        L, R = parse.(Int, split(readline()))
        S = vcat(S, L:R)
    end

    dp = zeros(Int, N)
    dp[1] = 1
    for i = 1:N
        for d = S
            if i+d > N continue end
            dp[i+d] += dp[i]
            dp[i+d] %= MOD
            dp[i+d] += MOD
            dp[i+d] %= MOD
        end
    end

    println(dp[N])
end

solve()
