n,k = list(map(int, input().split()))
numlist=[]
for i in range(k):
    l,r=list(map(int, input().split()))
    for j in range(l,r+1):
        numlist.append(j)
numlist.sort()
nlen=len(numlist)
count=[0]*(n+2)
count[0]=1
for i in range(n-1):
    for j in range(nlen):
        num=numlist[j]-1
        if i+1>num:
            count[i+1]=(count[i+1]+count[i-num])%998244353
print(count[i+1])