import numpy as np
num=input().split(' ')
count=0
plot=np.zeros([int(num[0]),int(num[0])])
t=[]
for a in range(int(num[1])):
  tmp=input().split(' ')
  t.append([int(tmp[0])+a for a in range(int(tmp[1])-int(tmp[0])+1)])
for a in range(int(num[0])):
  if a==0:
    plot[0,0]=1
  else:
    for posit in np.where(plot[a-1]>0)[0]:
      for b in t:
        for c in b:
          if posit+c<=int(num[0])-1:
	          plot[a,posit+c]+=plot[a-1,posit]
xx=int(np.sum(plot[:,int(num[0])-1]))
if xx>998244353:
  print((xx+1)%998244353)
else:
  print(xx)