
class Bit(val size: Int, val mod: Long) {
    private val array = LongArray(size){0}
    fun add(position: Int, value: Long): Unit {
        var pos = position
        while (pos < size){
            array[pos] = (array[pos] + value) % mod
            pos += pos.inv() and (pos + 1)
        }
    }
    operator fun get(position: Int): Long {
        var pos = position
        var result = 0L
        while (pos >= 0) {
            result = (result + array[pos]) % mod
            pos -= pos.inv() and (pos + 1)
        }
        return result
    }
}
fun main() {
    val MOD = 998244353L
    val (n, k) = readLine()!!.trim().split(' ').map(String::toInt)
    val ranges = List(k){
        val (left, right) = readLine()!!.trim().split(' ').map(String::toInt)
        left to right
    }
    val bit = Bit(n, MOD)
    bit.add(0, 1)
    bit.add(1, MOD - 1)
    for (i in 0 until n) {
        val current = bit[i]
        for ((left, right) in ranges) {
            if (i + left in 0 until n) {
                bit.add(i + left, current)
            }
            if (i + right + 1 in 0 until n) {
                bit.add(i + right + 1, MOD - current)
            }
        }
    }
    println((bit[n - 1] + MOD) % MOD)
}