fun main() {
    val (n, K) = readLine()!!.split(" ").map { it.toInt() }
    val s = Array(K) {
        readLine()!!.split(" ").map { it.toInt() }.let {
            Pair(it[0], it[1])
        }
    }

    val mod = 998244353L

    val dp = MutableList(n + 1) { 0L }
    val dpSum = MutableList(n + 1) { 0L }
    dp[1] = 1L

    for (i in 1 until n + 1) {
        for ((l, r) in s) {
            dp[i] = (dp[i] + ((if ((i - l) > 0) dpSum[i - l] else 0L) - (if ((i - r - 1) > 0) dpSum[i - r - 1] else 0L)) + mod) % mod
        }
        dpSum[i] = (dpSum[i - 1] + dp[i] + mod) % mod
    }
    println(dp[n])
}