object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, k = sc.nextInt()
  val lr = List.fill(k)((sc.nextInt(), sc.nextInt()))

  val mod = 998244353
  def plus(a: Long, b: Long): Long = (a + b) % mod
  def minus(a: Long, b: Long): Long = (a - b + mod) % mod

  val dp = Array.fill(n)(0L)
  val dpSum = Array.fill(n+1)(0L)
  dp(0) = 1
  dpSum(1) = 1
  for (i <- 1 until n) {
    for ((l, r) <- lr) {
      dp(i) = plus(dp(i), minus(dpSum((i-l+1).max(0)), dpSum((i-r).max(0))))
    }
    dpSum(i+1) = plus(dpSum(i), dp(i))
  }

  println(dp(n-1))
}
