n,k=map(int,input().split())
lr=[]
for i in range(k):
  l_,r_=map(int,input().split())
  lr.append([l_,r_])
ans=[0]*n


from itertools import accumulate

pra=0
minus=0
for i in range(n):
  
  if i==0:
    for l,r in lr:
      if r<=n-2:
        ans[l]+=1
        ans[r+1]+=-1
      else:
        if l<=n-1:
          ans[l]+=1
  if ans[i]==1:
    pra+=1
  elif ans[i]==-1:
    minus+=1
  if pra-minus>=1:
    for l,r in lr:
      if i+r<=n-2:
        ans[i+l]+=1
        ans[i+r+1]+=-1
      else:
        if i+l<=n-1:
          ans[i+l]+=1
   
ans=list(accumulate(ans))
print(ans[n-1]%998244353)


    


  