


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 memo = LongArray(n + 1){0L}
    memo[1] = 1
    memo[2] = -1
    for (pos in 1 .. n) {
        memo[pos] = (memo[pos] + memo[pos - 1] + MOD) % MOD
        for ((left, right) in ranges) {
            if (pos + left in memo.indices) {
                memo[pos + left] += memo[pos]
            }
            if (pos + right + 1 in memo.indices) {
                memo[pos + right + 1] -= memo[pos]
            }
        }
    }
    println((memo.last() + MOD) % MOD)
}