from functools import lru_cache

n, k = map(int, input().split())
a = set()
for i in range(k):
    l, r = map(int, input().split())
    for j in range(l, r + 1):
        a.add(j)
a = list(a)

x = [0] * n
x[0] = 1

@lru_cache
def mov(i):
    y = 0

    for d in a:
        if i == 1:
            return 1
        elif i - d >= 0:
            y += mov(i - d)
    return y


print(mov(n) % 998244353)