nk=input("").split(" ")
n=int(nk[0])
k=int(nk[1])
listp=[]
for i in range(n):
    listp+=[-1]
listp[0]=1
listlr=[]
for i in range(k):
    lr=input("").split(" ")
    listlr+=[[int(lr[0]),int(lr[1])]]
    



def funcp(n):
    if(listp[n-1]==-1):
        s=0
        for ii in range(k):
            for i in range(n-listlr[ii][1],n-listlr[ii][0]+1):
                if(i>0):
                    s+=funcp(i)
        s%=998244353
        listp[n-1]=s
        
        return s
    else:
        return listp[n-1]
print(funcp(n))
