N,K=map(int,input().split())
s=[0]*(N+1)
mod=998244353
l=[]
for i in range(K):
   a,b=map(int,input().split())
   for j in range(a,b+1):
      if s[j]==1:
         break
      s[j]=1
for i,j in enumerate(s):
   if j==1:
      l.append(i)
dp=[0]*(N+1)
dp[1]=1
for i in range(1,N+1):
   l=[k for k in l if k+i<=N]
   for j in l:
      dp[i+j]=(dp[i]+dp[i+j])%mod
print(dp[-1]%mod)