import strutils,sequtils
import algorithm,sets,lists,critbits,sequtils,intsets,strutils,tables,math,heapqueue,future,deques

const DIVISOR = 998244353

let read = iterator: string {.closure.} =
  while true:
    for s in stdin.readLine.split:
      yield s

let N, K = read().parseInt

var S = initHashSet[int]()
for _ in 1..K:
  let L, R = read().parseInt
  for i in L..R:
    S.incl(i)

let hops = S.toSeq().sorted()
var memo = newSeqWith(N+1, low(int))
memo[1] = 1

proc solve(i: int): int =
  if i < 0:
    return 0
  elif memo[i] != low(int):
    return memo[i]
  for j in hops:
    if i - j < 1:
      break
    result += solve(i-j)
    result = result mod DIVISOR
  memo[i] = result

echo solve(N)
