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

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d: String = " ") = str().split(d)
fun <T> list(d: String = " ", f: String.() -> T) = read(d).map { f(it) }
fun list() = list { toInt() }

fun <T> MutableList<T>.removeLast() = this.removeAt(this.lastIndex)

const val mod = 998244353L


fun main() {
    abc000X()
}
nooooooooooooooooo
fun abc000X() {
    val (n, k) = list()
    val a = Array(k) {
        val (t, u) = list()
        t to u + 1
    }

    val dp = LongArray(n) { 0L }
    dp[0] = 1
    for (i in 0..n - 2) {
        for ((t, u) in a) {
            if (i + t in dp.indices) {
                dp[i + t] += dp[i]
                dp[i + t] %= mod
            }
            if (i + u in dp.indices) {
                dp[i + u] += mod - dp[i]
                dp[i + u] %= mod
            }
        }
        System.err.println(dp.joinToString())
    }
    println(dp.last())
}
