N,K=map(int,input().split())

arr={0}
for i in range(K):
    a,b=map(int,input().split())
    arr|=set([j for j in range(a,b+1)])

arr.discard(0)


dp=[0]*N 
dp[0]=1

ans=0
for i in range(N):
    for j in arr:
        if i+j<=N-1:
            dp[i+j]+=dp[i]
    
    
print(dp[-1]%998244353)