from functools import lru_cache
import sys

sys.setrecursionlimit(10**9)

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)


@lru_cache(maxsize=None)
def mov(i):
    y = 0
    if i == 1:
        return 1

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


print(mov(n) % 998244353)