from collections import deque
import bisect

N, K = list(map(int, input().split(" ")))
S = []
for _ in range(K):
    a, b = list(map(int, input().split(" ")))
    S.extend(range(a, b+1))


combinations = [0] * (N + 1)
combinations[1] = 1
checked = [False] * (N + 1)
S.sort()
next_node = []
for i in S:
    next_node.append(i + 1)
    combinations[i + 1] += 1
next_node = deque(next_node)
while len(next_node) > 0:
    node = next_node.popleft()
    if checked[node]:
        # check済みならskip
        continue
    else:
        checked[node] = True
    for i in S:
        next_idx = node + i
        if next_idx > N:
            break
        else:
            combinations[next_idx] += combinations[node]
            if combinations[next_idx] >= 998244353:
                combinations[next_idx] = combinations[next_idx] % 998244353
            bisect.insort_left(next_node, next_idx)
print(combinations[-1])