import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.min

fun main(args: Array<String>) {

    // IO Templates
    val br = BufferedReader(InputStreamReader(System.`in`))
    val out = PrintWriter(System.out)

    val (n, k) = br.readLine()!!.split(' ').map { it.toInt() }

    val lrs = Array(k) { 0 to 0 }

    for (i in 0 until k) {
        val (l, r) = br.readLine()!!.split(' ').map { it.toInt() }
        lrs[i] = (l to r+1)
    }

    val dp = LongArray(n + 10)
    val dif = LongArray(n + 10)
    dp[1] = 1
    dif[2] = -1

    for (i in 1 until n) {
        for (j in 0 until k) {
            val (l, r) = lrs[j]
            if (i + l <= n) {
                dif[i + l] += dp[i]
                dif[i + l] % MyMod.MOD
            }
            if (i + r <= n) {
                dif[i + r] -= dp[i]
                dif[i + r] % MyMod.MOD
            }
            dp[i + 1] = (dp[i] + dif[i + 1]) % MyMod.MOD
        }
    }

    out.println((dp[n] + MyMod.MOD) % MyMod.MOD)

    out.flush()
}

class MyMod(var value: Long = 0L) {
    operator fun plus(a: Long) {
        value = plus(value, a)
    }

    operator fun minus(a: Long) {
        value = minus(value, a)
    }

    operator fun times(a: Long) {
        value = times(value, a)
    }

    operator fun div(a: Long) {
        value = div(value, a)
    }

    operator override fun equals(other: Any?): Boolean {
        // FIXME: 2020/08/30 定義途中
        return super.equals(other)
    }

    companion object {
        const val MOD: Long = 998244353L
        fun plus(a: Long, b: Long): Long {
            return (a % MOD + b % MOD) % MOD
        }

        fun minus(a: Long, b: Long): Long {
            return (a % MOD - b % MOD + MOD) % MOD
        }

        fun times(a: Long, b: Long): Long {
            return (a % MOD) * (b % MOD) % MOD
        }

        fun div(a: Long, b: Long): Long {
            return (a % MOD) * (pow(b, MOD - 2) % MOD) % MOD
        }

        // calc a^b
        // b <= 0 は1を返す
        fun pow(a: Long, b: Long): Long {
            var a = a
            var b = b
            var result = 1L
            a %= MOD
            while (b > 0) {
                if (b % 2 == 1L) result = result * a % MOD
                a = a * a % MOD
                b = b shr 1
            }
            return result
        }

        // calc inverse element
        fun invEle(a: Long): Long {
            return pow(a % MOD, MOD - 2) % MOD
        }
    }

}