mod=998244353
N,K=map(int,input().split())
_S=[]
for _ in range(K):
    l,r=map(int,input().split())
    _S+=list(range(l,r+1))
S=sorted(_S)
dp=[0]*(N+1)
dp[1]=1
for i in range(1,N-S[0]+1):
    for s in S:
        if s+i>N:
            S.remove(s)
            break
        dp[i+s]+=dp[i]
        dp[i+s]%=mod
print(dp[N])