parseline(str=readline()) = parse.(Int, split(str))
function main()
    N, K = parseline()
    LR = [Int[] for _ in 1:K]
    Mod = 998244353
    for k in 1:K
        LR[k] = parseline()
    end
    dp = zeros(Int, N)
    dp[1] = 1
    dp[2] = -1
    for n in 1:N
        for (l, r) in LR
            n+l≤N && (dp[n+l] = mod(dp[n+l]+dp[n], Mod))
            n+r+1 && (dp[n+r+1] = mod(dp[n+r+1]-dp[n]+Mod, Mod))
        end
        dp[n+1] = dp[n]
    end
    println(dp[end])
end
main()