n,k=map(int,input().split())
mod=998244353

dp=[0]*(n+1)
dp[0]=1
s=[]
for i in range(k):
    l,r=map(int,input().split())
    s.extend( [j for j in range(l,r+1)] )

for i in range(1,n+1):
    tmp=0
    for j in range(len(s)):
        tmp+=dp[i-s[j]]
    dp[i]=tmp%mod
print(dp[-2])
