import sys
input = sys.stdin.readline

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

L = [list(map(int, input().split())) for _ in range(K)]

S = set()

for left, right in L:
    S = S | set(range(left, right+1))

S = sorted(list(S))

n_list = [0] * N
n_list[0] = 1

for idx, value in enumerate(n_list):
    if value == 0:
        continue
    if S[0] + idx >= N:
        break
    for s in S:
        next_idx = s + idx
        if next_idx >= N:
            break
        n_list[next_idx] += value

print(n_list[-1] % 998244353)
