import numpy
import queue

N, K = map(int, input().split())
S = []
for i in range(K):
    L, R = map(int, input().split())
    S.extend(range(L, R + 1))

i = 1
q = queue.Queue()
for s in S:
    q.put((i, s))

ans = 0
i = 1
while True:
    if q.empty():
        break

    a, b = q.get()

    if N < a + b:
        continue

    if N == a + b:
        ans += 1
        ans = ans % 998244353

    for s in S:
        q.put((a + b, s))

print(ans)