q = 998244353

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

S = []
for _ in range(K):
    l, r = map(int, input().split())
    S.extend(list(range(l, r+1)))

S.sort()

result = [0] * N
result[0] = 1

for i in range(N):
    for s in S:
        if i + s < N:
            result[i + s] = (result[i + s] + result[i]) % q
        else:
            break

print(result[-1])