n,k=map(int,input().split())
s=[]
for _ in range(k):
    l,r=map(int,input().split())
    temp=list(range(l,r+1))
    s+=temp
s=sorted(s)
ans=[0]*(10**6)
ans[0]=1
for i in range(n-1):
    ans[i]=ans[i]%99824435
    for j in s:
        ans[i+j]+=ans[i]
print(ans[n-1]%998244353)