n,k=list(map(int, input("").split()))
s=[]
for i in range(k):
    l,r=list(map(int, input("").split()))
    for j in range(l,r+1):
        s.append(j)
s=list(set(s))
o=[0]*(n+1)
o[1]=1
for i in range(2,n+1):
    for j in s:
        if i-j > 0 :
            o[i]+=o[i-j] 
print(o[n]%998244353)