import itertools
n,k = map(int,input().split())
lr = []
for _ in range(k):
    a,b = map(int,input().split())
    lr.append(list(range(a,b+1)))
lr = list(itertools.chain.from_iterable(lr))
count = [0] * (n + 1)
for a in lr:
    count[a] = 1
for i in range(n):
    for j in lr:
        if count[i-j] > 0 and i-j > 0:
            count[i] += count[i-j]
print(count[-2] % 998244353)