import numpy

q = 998244353

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

S = []
for _ in range(K):
    S.append(list(map(int, input().split())))
S.sort()

result = numpy.zeros(N, dtype=int)
result[0] = 1

for i in range(N):
    for l, r in S:
        if i + l >= N:
            break
        if i + r >= N:
            r = N - i - 1
        result[i + l:i + r + 1] = (result[i + l:i + r + 1] + result[i]) % q

print(result[-1])