fun main() {
    val nk = readLine()!!.split(" ")
    val n = nk[0].toInt()
    var k = arrayListOf<Int>()
    val l = LongArray(size = 200000)

    for (i in (0 until nk[1].toInt())) {
        val lr = readLine()!!.split(" ")
        k.addAll(lr[0].toInt() .. lr[1].toInt())
    }
    k.sort()

    l[0] = 1

    for (i in (0 until n)){
        for (x in k) {
            if (i + x >= n) {
                break
            }
            l[i + x] += l[i]
        }
    }
    print(l[n - 1] % 998244353)
}