from itertools import *
n, k = map(int, input().split())
mod = 998244353
strides = []
for i in range(k):
  l, r = map(int, input().split())
  for t in range(l, r + 1):
    strides.append(t)
strides.sort()

d = [0] * (n + 1)  # マスに対応
d[0] = 1
for i in range(1, n):
  for stride in strides:
    if i >= stride:
      d[i] += d[i - stride]
  d[i] %= mod
print(d[n-1])