# 179 D

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

s = []
for _ in range(k):
    l,r = map(int,input().split())
    s.extend(range(l,r+1))

memo = {}

for i in range(1, n+max(s)+1):
  memo[i] = 0
  
for i in range(1, n):
  if i in s:
    memo[i] += 1
  for e in s:
    memo[i+e] += memo[i]

    

print(memo[n-1]%998244353)



