import java.math.BigInteger

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

  val dp = Array(N) { BigInteger.ZERO }
  dp[0] = BigInteger.ONE
  val ds = Array(N) { BigInteger.ZERO }
  ds[0] = BigInteger.ONE

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

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

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() }
