N,K=map(int,input().split())
dp=[0]*(N)
dp[0]=1
mod=998244353
L=list()
for i in range(K):
  a,b=map(int,input().split())
  L.append([a,b])
for i in range(N):
  for j in range(K):
    a,b=L[j]
    if i>=b:
      dp[i]+=sum(dp[i-b:i-a+1])
    elif i>=a:
      dp[i]+=sum(dp[:i-a+1])
    dp[i]%=mod
print(dp[-1])