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