fun main() {
  val MOD = 998244353
  val (N, K) = readInts()
  val LR = (1..K).map { readInts() }

  val dp = Array(N) { 0 }
  dp[0] = 1
  val ds = Array(N) { 0 }
  ds[0] = 1

  fun getRangeSum(l: Int, r: Int): Int {
    val L = if (l < 1) 0 else ds[l - 1]
    val R = if (r < 0) 0 else ds[r]
    return if (R >= L) R - L else R - L + MOD
  }

  for (i in 1 until N) {
    var sum = 0
    LR.forEach { (l, r) ->
      sum = (sum + getRangeSum(i - r, i - l)) % MOD
    }
    dp[i] = sum
    ds[i] = (ds[i - 1] + sum) % MOD
  }
  println(dp.last())
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }
