
import scala.annotation.tailrec
import scala.io.StdIn
import scala.collection.mutable

object Main extends App {
  val Array(n,k) :Array[Long]= StdIn.readLine().split(' ').map(_.toLong)
  val lrList = for(i <- 1L to k)yield{
    val Array(l,r) = StdIn.readLine().split(' ').map(_.toLong)
    (l,r)
  }

  var memo = mutable.Map.empty[Long,BigInt]
  def getPathCombination(position:Long):BigInt=
    memo.getOrElse(position,{
      val ans =
        if(position == n) BigInt(1)
        else if (position > n) BigInt(0)
        else
          (for((l,r) <- lrList;
               i <- l to r
               if position + i <= n)yield {
            getPathCombination(position + i)
          }).sum
      memo(position) = ans
      ans
    })


  println(getPathCombination(1) % 998244353)
}





