N,K=map(int,input().split())
S=[]
NUM=998244353
for _ in range(K):
    l,r=map(int,input().split())
    for i in range(l,r+1):
        S.append(i)
S.sort()
dp=[0]*(N+1)
dp[1]=1
for i in range(2,N+1):
    for s in S:
        if i-s<=0: break
        dp[i]+=dp[i-s]
        dp[i]%=NUM

print(dp[N])
