import sys

input = sys.stdin.readline

N, K = map(int, input().split())
steps = []
for _ in range(K):
    l, r = map(int, input().split())
    for i in range(l, r + 1):
        steps.append(i)

steps = tuple(steps)
mod = 998244353

d = dict()
d[0] = 1
for i in range(1, N):
    c = 0
    for s in steps:
        if i - s >= 0:
            c += d[i - s]
            c %= mod
    d[i] = c

print(d[N-1])