mod = 998244353
N, K = map(int, input().split())

LR = [map(int, input().split()) for _ in range(K)]
L, R = [list(i) for i in zip(*LR)]

a = []
for i in range(K):
  a.extend(list(range(L[i], R[i] + 1)))
LR = list(set(a))

print(LR)
DP = [0]*N
DP[0] = 1
for i in range(N):
  if i + LR[-1] > N:
    LR.pop(-1)
  if len(LR) < 1:
    break
  
  for s in LR:
    local = i + s
    if local < N:
      DP[local] += DP[i]


print(DP[N-1] % mod)