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

n, k = map(int, input().split())
MOD = 998244353


lr = []
for _ in range(k):
    l, r = map(int, input().split())
    lr += (list(range(l, r + 1)))

lr.sort(reverse=True)


@lru_cache(maxsize=None)
def rec(n):
    if n == 1:
        return 1
    else:
        ans = 0
        for k in lr:
            if n - k >= 1:
                ans += rec(n - k)
                ans %= MOD
    return ans


print(rec(n))