import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=998244353
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  field=[LI() for _ in range(k)]
  field.sort()

  rng=[]
  for x,y in field:
    for z in range(x,y+1):
      rng.append(z)

  # print(rng)

  dp=[0]*(n+1)
  dp[1]=1

  for i in range(1,n):
    for dx in rng:
      if i+dx>n:
        break
      dp[i+dx]+=dp[i]
      dp[i+dx]%=mod
    # print(dp)
  
  return dp[n]%mod

# main()
print(main())
