n,k=map(int,input().split())
route=[]
mod=998244353
for i in range(k):
  l,r=map(int,input().split())
  for j in range(l,r+1):
    route.append(j)
route.sort()
num=[0]*(n)
num[0]=1
for i in range(n):
  for j in route:
    try:
      num[i+j]+=num[i]
      num[i+j]%=mod
    except:
      break
print(num[n-1])
