from collections import defaultdict
dp=defaultdict(int)
mod1,mod2=10**9+7,998244353
mod=mod2

n,k=map(int,input().split())
f=0
dp[1]=1
ls=[tuple(map(int,input().split())) for i in range(k)]

#   [i-1-l,i-1-r]
#   [ i-l, i-r ]
for i in range(1,1+n):
    for r,l in ls:
        f=(f+-dp[i-1-l]+dp[i-r])%mod
    dp[i]=(dp[i]+f)%mod
print(dp[n])