import sequtils,strutils,strformat,algorithm,math,sugar,bitops
import tables,heapqueue,sets,options,rationals
#proc mod2(n, M: int):int{.used.}=(if M==0: 0 else: ((n mod M) + M) mod M)
proc scanf(fmt: cstring){.header: "<stdio.h>", varargs.}
proc inpStr:string{.used.}=((result=""; var buf: array[256, char]; scanf("%s",
  buf)); for b in buf: ((if b==chr(0): break); result.add(b)))
proc inp:int{.used.}=scanf("%lld", addr result)
template newSeqWith(y, x: int, p: untyped):untyped{.used.}= newSeqWith(y, newSeqWith(x, p))
{.warning[UnusedImport]:off.}

when true: #modint
  #https://github.com/Muratam/yukicoder-nim/blob/master/lib/mathlib/modint.nim
  const MOD* = 998244353
  type ModInt* = object
    v*:int # 0~MODに収まる
  proc toModInt*(a:int) : ModInt =
    if a < -MOD : result.v = ((a mod MOD) + MOD) mod MOD
    elif a < 0 : result.v = a + MOD
    elif a >= MOD: result.v = a mod MOD
    else: result.v = a
  proc `+`*(a,b:ModInt) : ModInt =
    result.v = a.v + b.v
    if result.v >= MOD : result.v = result.v mod MOD
  proc `*`*(a,b:ModInt) : ModInt =
    result.v = a.v * b.v
    if result.v >= MOD : result.v = result.v mod MOD
  proc `^`*(a:ModInt,b:int) : ModInt =
    if a.v == 0 : return 0.toModInt()
    if b == 0 : return 1.toModInt()
    if b == 1 : return a
    if b > MOD: return a^(b mod (MOD-1)) # フェルマーの小定理
    let pow = a^(b div 2)
    if b mod 2 == 0 : return pow * pow
    return pow * pow * a
  proc `+`*(a:int,b:ModInt) : ModInt = a.toModInt() + b
  proc `+`*(a:ModInt,b:int) : ModInt = a + b.toModInt()
  proc `-`*(a:ModInt,b:int) : ModInt = a + (-b)
  proc `-`*(a,b:ModInt) : ModInt = a + (-b.v)
  proc `-`*(a:int,b:ModInt) : ModInt = a.toModInt() + (-b.v)
  proc `*`*(a:int,b:ModInt) : ModInt = a.toModInt() * b
  proc `*`*(a:ModInt,b:int) : ModInt = a * b.toModInt()
  proc `/`*(a,b:ModInt) : ModInt = a * b^(MOD-2)
  proc `$`*(a:ModInt) : string = $a.v

let N,K = inp()
var S = newSeq[bool](N+1)

for i in 0..<K:
  let L,R = inp()
  for j in L..R:
    S[j] = true

var dp = newSeqWith(N+1,0)
dp[N] = 1

for i in countdown(N-1,1):
  var tmp = 0.toModInt()
  for j in i+1..N:
    if S[j-i]:
      tmp = tmp + dp[j]
  dp[i] = tmp.v

#dump(S)
#dump(dp)
echo dp[1]