from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

mod=998244353

n,k=nii()
hanni=[]
for i in range(k):
  l,r=nii()
  hanni+=[j for j in range(l,r+1)]

dp=[0]*n
dp[0]=1
for i in range(n):
  for j in hanni:
    if i-j>=0:
      dp[i]+=dp[i-j]
      dp[i]=dp[i]%mod

print(dp[-1])
