q = 998244353

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

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

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

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

print(result[-1])