n,k=map(int,input().split())
mod=998244353
step=set()
for i in range(k):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        step.add(j)
step=list(step)
dp=[0]*(n+1)
dp[0]=1
for i in range(n):
    for x in step:
        if i+x>n:
            break
        dp[i+x]+=dp[i]
        dp[i+x]%=mod
print(dp[n-1])