import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 8)


N, K = map(int, input().split())
M = 998244353
S = set()
for _ in range(K):
    L, R = map(int, input().split())
    for i in range(L, R + 1):
        S.add(i)


@lru_cache(None)
def dp(i):
    if i < 1:
        return 0
    elif i == 1:
        return 1
    else:
        res = 0
        for d in S:
            res += dp(i - d)
            res %= M
        return res
print(dp(N) % M)