N, K=map(int, input().split())
wa = set([])
for _ in range(K):
  l, r =map(int, input().split())
  [wa.add(i) for i in range(l,r+1)]
wa = sorted(list(wa))
if wa[0]!=1:
  print(0)
  exit()
from collections import deque
wa = deque(wa)
dp = [0]*N
dp[0]=1
koma = wa.popleft()
sakanoboru = []
waru = 998244353
for i in range(1,N):
  if koma == i:
    sakanoboru.append(koma)
    if wa: koma = wa.popleft()
  for j in sakanoboru:
    dp[i]+=dp[i-j]%waru
print(dp[-1]%waru)