n,k=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(k)]
mod=998244353
dp=[0]*n
dp[0]=1
for i in range(n):
  if i>1:
    dp[i]+=dp[i-1]
    dp[i]%=mod
  for l,r in lr:
    if i+l<n:
      dp[i+l]+=dp[i]
      dp[i+l]%=mod
    if i+r+1<n:
      dp[i+r+1]-=dp[i]
      dp[i+r+1]%=mod
print(dp[-1]%mod)
