n,k=map(int,input().split())

s = set()
for i in range(k):
  l,r = map(int,input().split())
  tmp = set(list(range(l,r+1)))
  s = s|tmp

dp=[0]*(n+1)
dp[1]=1
for i in range(2,n+1):
  for ss in s:
    dp[i]+=dp[i-ss]

print(dp[n]%998244353)
