N,K=map(int,input().split())
step=[]
for i in range(K):
    l,r=map(int,input().split())
    for i in range(l,r+1):
        step.append(i)
        
dp=[0]*(N+1) #jマス目へ行く方法の個数を収納
dp[1]=1
mod=998244353

for i in range(2,N+1):
    for x in step:
        if i >= x+1:
            dp[i] += dp[i-x]
            dp[i] %= mod
            
print(dp[N])