import sys
sys.setrecursionlimit(500*500)

N, K = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(K)]

minL = min(i[0] for i in LR)

mod = 998244353

result = [None for _ in range(N)]
result[0] = 1
#for ni in range(1, N):
def dp(ni):
  if result[ni] is not None: return result[ni]
  result[ni] = 0
  for l, r in LR:
    for j in range(l, r+1):
      if ni-j<0: continue
      result_ni_j = dp(ni-j) if result[ni-j] is None else result[ni-j]
      result[ni] = (result[ni]+result_ni_j) % mod
  return result[ni]


print(dp(N-1))
