mod=998244353
n,k=map(int,input().split())
step=[]
for i in range(k):
    l,r=map(int,input().split())
    for p in range(l,r+1):
        step.append(p)
step=sorted(step)
dp=[0 for i in range(n+1)]
dp[1]=1
for i in range(1,n+1):
    for s in step:
        if i+s<=n:
            dp[i+s]+=dp[i]
        else:
            break
print(dp[n]%mod)