n,k=list(map(int,input().split()))
arr=[]
for i in range(k):
    arr.append(list(map(int,input().split())))
    
mod=998244353
m=len(arr)
dp=[0]*(n+1)
dp[1]=1
for i in range(2,n+1):
    cnt=0
    for k in arr:
        for j in range(k[0],k[1]+1):
            if i-j>0:
                cnt=(cnt+dp[i-j])%mod
            else:
                break
    dp[i]=cnt
        
print(dp[n])

        
    
