N, K = list(map(int, input().split(" ")))
S = []
for _ in range(K):
    a, b = list(map(int, input().split(" ")))
    S.extend(range(a, b+1))


combinations = [0] * (N + 1)
combinations[1] = 1
S.sort()
for i in range(1, (N + 1 - S[0])):
    for j in S:
        idx = i + j
        if idx < N + 1:
            combinations[idx] += combinations[i]
            if combinations[idx] >= 998244353:
                combinations[idx] = combinations[idx] % 998244353
        else:
            break
print(combinations[-1])