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

idou = set()
for i in range(0, K):
    L, R = map(int, input().split())
    idou = idou | set(range(L, R + 1))

idou = list(idou)

moves = [0] * N
moves[0] = 1
for i in range(0, N):
    for j in range(0, len(idou)):
        if i + idou[j] < N:
            moves[i + idou[j]] += moves[i]

print(moves[N - 1] % 998244353)
