import itertools
n,k = map(int, input().split())

dp = [0] * (n+2)
dp[1] = 1
step = []

for i in range(k):
  l,r = map(int, input().split())
  step.append(list(range(l,r+1)))

step = sorted(list(set(list(itertools.chain.from_iterable(step)))))
max_step = len(step) - 1
ok_step = 0
step_iter = 0

if step[0] == 1:
  ok_step = 1
  step_iter = 1

for i in range(2,n+1):
  if step[step_iter]+1 == i:
    ok_step += 1
    if step_iter != max_step:
      step_iter += 1
  for j in range(ok_step):
    dp[i] += dp[i-step[j]] % 998244353
    
print(dp[n]%998244353)