n,k=map(int,input().split())
mod=998244353
S=[]
for _ in range(k):
  l,r=map(int,input().split())
  S.append([l,r])
dp=[0 for _ in range(n+1)]
for i in range(k):
  for j in range(S[i][0],S[i][1]+1):
    dp[j]+=1

for i in range(1,n+1):
  for j in range(k):
    for l in range(S[j][0],S[j][1]+1):
      if i-l<1:
        continue
      dp[i]+=dp[i-l]
print(dp[n-1]%mod)