N, K = map(int, input().split())
LR = []
for i in range(K):
    LR.append(list(map(int, input().split())))

D = 998244353

Number = []
for lr in LR:
    Number.extend(range(lr[0],lr[1]+1))

position = 1
queue = []
for num in Number:
    temp = num + position
    if temp <= N:
        queue.append(num+position)

count = 0

while(True):
    if len(queue) == 0:
        break
    if queue[0] == N:
        count += 1
        del queue[0]
    else:
        for num in Number:
            temp = queue[0] + num
            if temp <= N:
                queue.append(num+queue[0])
        del queue[0]

print(count%D)