n,k=map(int,input().split())
mod=998244353
S=set()
for _ in range(k):
  l,r=map(int,input().split())
  S|={i for i in range(l,r+1)}
dp=[0 for _ in range(n+1)]
for i in S:
  dp[i]=1

for i in range(1,n+1):
  for j in S:
    if i-j<1:
      continue
    dp[i]+=dp[i-j]
print(dp[n-1]%mod)