p = 998244353

n, k = list(map(int, input().split()))

LRs = []

for j in range(k):

    lj, rj = list(map(int, input().split()))

    LRs.append((lj, rj))

A = [0] * (n + 1)

i0 = min(lj for lj, rj in LRs)

A[0] = 1

A[i0] = 1

for i in range(i0 + 1, n):

    A[i] = A[i - 1]

    for j in range(k):

        lj, rj = LRs[j]

        if i - lj >= 0:

            A[i] += A[i - lj]

        if i - 1 - rj >= 0:

            A[i] -= A[i - 1 - rj]

        A[i] %= p

print((A[n - 1]))

p = 998244353

n, k = list(map(int, input().split()))

LRs = [tuple(map(int, input().split())) for _ in range(k)]

A = [0] * (2 * n + 1)

for lj, rj in LRs:

    A[lj] += 1

    A[rj + 1] -= 1

s = 0

for i in range(1, n):

    s = (s + A[i]) % p

    for lj, rj in LRs:

        A[i + lj] += s

        A[i + rj + 1] -= s

print(s)

p = 998244353
n, k = list(map(int, input().split()))
LRs = []
for j in range(k):
    lj, rj = list(map(int, input().split()))
    LRs.append((lj, rj))
A = [0] * (n + 1)
i0 = min(lj for lj, rj in LRs)
A[0] = 1
A[i0] = 1
for i in range(i0 + 1, n):
    A[i] = A[i - 1]
    for j in range(k):
        lj, rj = LRs[j]
        if i - lj >= 0:
            A[i] += A[i - lj]
        if i - 1 - rj >= 0:
            A[i] -= A[i - 1 - rj]
        A[i] %= p
print((A[n - 1]))

p = 998244353
n, k = list(map(int, input().split()))
LRs = [tuple(map(int, input().split())) for _ in range(k)]
A = [0] * (2 * n + 1)
for lj, rj in LRs:
    A[lj] += 1
    A[rj + 1] -= 1
s = 0
for i in range(1, n):
    s = (s + A[i]) % p
    for lj, rj in LRs:
        A[i + lj] += s
        A[i + rj + 1] -= s
print(s)

-LRs = [] -for j in range(k): -    lj, rj = list(map(int, input().split())) -    LRs.append((lj, rj)) -A = [0] * (n + 1) -i0 = min(lj for lj, rj in LRs) -A[0] = 1 -A[i0] = 1 -for i in range(i0 + 1, n): -    A[i] = A[i - 1] -    for j in range(k): -        lj, rj = LRs[j] -        if i - lj >= 0: -            A[i] += A[i - lj] -        if i - 1 - rj >= 0: -            A[i] -= A[i - 1 - rj] -        A[i] %= p -print((A[n - 1])) +LRs = [tuple(map(int, input().split())) for _ in range(k)] +A = [0] * (2 * n + 1) +for lj, rj in LRs: +    A[lj] += 1 +    A[rj + 1] -= 1 +s = 0 +for i in range(1, n): +    s = (s + A[i]) % p +    for lj, rj in LRs: +        A[i + lj] += s +        A[i + rj + 1] -= s +print(s)