mod=998244353
n,k=map(int,input().split())
s=set()
for i in range (k):
    x,y=map(int,input().split())
    for m in range (x,y+1):
        s.update([m])

dp=[0 for i in range (n+1)]
dp[1]=1


for i in range (2,n+1):
    x=0
    for val in s:
        if (i-val)<0:
            continue
        x=(x%mod+(dp[i-val]%mod))%mod
    dp[i]=x

print (dp[n])
