n, k = map(int, input().split())
s = set()
ans = [0]*n + [1]
for _ in range(k):
  a, b = map(int, input().split())
  i = a
  while i<=b:
    s.add(i)
    i = i + 1

for i in reversed(range(1, n)):
  for j in s:
    if i + j <= n:
      ans[i] = ans[i] + ans[i+j]
print(ans[1]%998244353)