n,k=map(int,input().split())
s=set()
for i in range(k):
  l,r=map(int,input().split())
  for ll in range(l,r+1):
    s.add(ll)
dp=[0]*(n+1)
dp[1]=1
mod=998244353

for i in range(n):
  for ss in s:
    if i+ss<=n:
      dp[i+ss]+=dp[i]
      dp[i+ss]%=mod
print(dp[-1]%mod)