import collections
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))

table = collections.defaultdict(int)
table[1] = 1
for num in range(1, n+1):
    for i in s:
        if num + i > n:
            break
        table[num+i] += table[num]
        table[num+i] %= 998244353

print(table[n])
