from collections import deque
N, K = map(int, input().split())

S = []
for k in range(K):
    L, R = map(int, input().split())
    for n in range(L, R+1):
        S += [n]


q = deque()
q.append(0)

boxes = [0 for n in range(N)]
while q:
    i = q.popleft()
    for s in S:
        if i + s >= N:
            continue
        boxes[i + s] += 1
        q.append(i+s)


print(boxes[-1] % 998244353)
