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

move_list = []
for i in range(K):
    L, R = map(int, input().split())
    for j in range(L, R + 1):
        move_list.append(j)

ans_list = [0 for _ in range(N)]
ans_list[-1] = 1

for i in range(N - 1, -1, -1):
    for j in range(len(move_list)):
        step = move_list[j]
        idx = i - step
        if idx < 0:
            continue
        ans_list[idx] += ans_list[i]
ans_num = ans_list[0]
ans_num = ans_num % 998244353
print(ans_num)