def coun(x,i):
    if dp[i]!=0:
        return dp[i]
    else:
        for j in x:
            if (j+i)<=n-1:
                dp[i]+=coun(x,i+j)
        return dp[i]

n,k=map(int,input().split())
x=[]
for i in range(k):
    a,b= map(int,input().split())
    for j in range(a,b+1):
        x.append(j)
mod=998244353
dp=[0]*n
dp[-1]=1
print(coun(x,0)%mod)
