N, K = map(int, input().split())
MOD = 998244353
nums = []
for _ in range(K):
    inp = list(map(int, input().split()))
    nums += [i for i in range(min(inp), max(inp) + 1)]
nums = list(set(nums))


ns = [0 for _ in range(N)]
ns[0] = 1
for i in range(1, N):
    for j in range(0, i):
        if i - j in nums:
            ns[i] += ns[j]
print(ns[-1] % MOD)
