PRIME = 998244353
n, k = map(int, input().split())
a = [0 for i in range(n + 1)]
a[1] = 1

l = []
r = []

for i in range(k):
  _l, _r = map(int, input().split())
  l.append(_l)
  r.append(_r)

for i in range(1, n):
  for j in range(k):
    if i + l[j] <= n:
      a[i + l[j]] += 1
    if i + r[j] + 1 <= n:
      a[i + r[j] + 1] += PRIME - 1

for i in range(1, n + 1):
  a[i] = (a[i - 1] + a[i]) % PRIME

print(a[n] % PRIME)