N, K = map(int, input().split())
S = set()
for _ in range(K):
  L, R = map(int, input().split())
  for lr in range(L, R + 1):
    S.add(lr)
S = list(S)
DP = [0] * N
DP[0] = 1
for i in range(N):
  for s in S:
    if 0 <= i - s < N:
      DP[i] += DP[i - s]
print(DP[-1]%998244353)