n,k=map(int,input().split())
s=[]
dp=[0,1]
for i in range(k):
  a,b=map(int,input().split())
  if b==n:
    s.extend(list(range(a,b)))
  else:
    s.extend(list(range(a,b+1)))
s.sort()
for i in range(2,n+1):
  tmp=0
  for j in s:
    if i-j>=1:
      tmp+=dp[i-j]
    else:
      break
  dp.append(tmp%998244353)
print(dp[-1])