import itertools
N, K = map(int, input().split())

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

DP = [0]*N
DP[0] = 1
for i in range(N):
  for s in LR:
    local = i + s
    if local < N:
      DP[local] += DP[i]
print(DP[N-1] % 998244353)