import java.util.*
import kotlin.math.*

fun main() {
    val mod = 998244353L

    val (n, k) = readIntList()
    val range = List(k) { readIntList() }

    val dp = LongArray(n + 1)
    val dpSum = LongArray(n + 1)
    dp[1] = 1L
    dpSum[1] = 1L

    for (i in 2..n) {
        for ((l, r) in range) {
            val li = max(i - r, 1)
            val ri = i - l
            if (ri < 0) continue
            dp[i] += (dpSum[ri] - dpSum[li - 1]) % mod
        }
        dpSum[i] = (dpSum[i - 1] + dp[i]) % mod
    }
    println(dp[n])
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)