import sys
sys.setrecursionlimit(300000)
N, K = map(int, input().split())

pool = []
for _ in range(K):
  L, R = map(int, input().split())
  pool += list(range(L, R+1))

ex = [False] * (N+1)
memo = [0] * (N+1)
ex[0] = True
memo[0] = 1

def calc(n):
  if not ex[n]:
    memo[n] = sum([calc(n-i) for i in pool if (n-i) >= 0]) % 998244353
  ex[n] = True
  return memo[n]

_ = calc(N)
print(memo[-2])