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

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

memo = {}

def dest(n):
  return sum([memo[n-i] for i in s if n-i in memo])

print(s)

for i in range(1, n):
  memo[i] = dest(i) % 998244353
  if i in s:
    memo[i] += 1
    

print(memo[n-1])


