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
    for n in 1:N
        dp[n] == 0 && continue
        for (l, r) in LR
            n+l > N && continue
            next = (n+l):min(N, n+r)
            dp[next] .+= dp[n]
            dp[next] = mod.(dp[next], Mod)
        end
    end
    println(dp[end])
end
main()