def get():
    return [int(x) for x in input().split()]

n, k = get()
s = set()
for _ in range(k):
    start, end = get()
    [s.add(x) for x in range(start, end+1)]
memo = {}
def rec(N):
    if N < 1:
        return 0
    elif N == 1:
        return 1
    ans = 0
    for i in s:
        if i > N:
            break
        if N-i not in memo:
            memo[N-i] = rec(N-i)
        ans += memo[N-i]
        ans %= 998244353
    return ans
print(rec(n))