n,k=map(int,input().split())
mod=998244353
s=set()
for _ in range(k):
  l,r=map(int,input().split())
  for j in range(l,r+1):
    s.add(j)
m=len(s)
dp=[0]*n
dp[0]=1
for i in range(1,n):
  for j in s:
    if i-j>=0:
      dp[i]+=dp[i-j]
print(dp[n-1]%mod)
