import sys
readline=sys.stdin.readline

N,K=map(int,readline().split())
DIV = 998244353
steps = []
for i in range(K):
  l,r = map(int,readline().split())
  for j in range(l, r + 1):
    steps.append(j)
    
steps = sorted(steps)

dp = [0] * (N)
dp[0] = 1
for i in range(len(dp)):
  for s in steps:
    if i + s >= len(dp):
      break
    dp[i + s] += dp[i]
    dp[i + s] %= DIV
    
print(dp[-1])
