n,k=map(int, input().split())
alist=[]
for i in range(k):
  a,b=map(int, input().split())
  for i in range(a,b+1):
    alist.append(i)
blist=[0]*(2*n+2)
blist[0]=1
for i in range(n):
  for j in alist:
    blist[i+j]=(blist[i]+blist[i+j])%998244353
print(blist[n-1])