n, k = map(int, input().split())
section = [0] * (n + 2)

for i in range(k):
    left, right = map(int, input().split())
    section[left] += 1
    section[right + 1] -= 1

numbers = []
cnt = 0
for i in range(1, n + 1):
    cnt += section[i]
    if 0 < cnt:
        numbers.append(i)

    
d = [0] * (n + 1)
d[1] = 1

for i in range(1, n + 1):
    for j in numbers:
        if i - j <= 0:
            continue
    
        d[i] += d[i - j]
        d[i] %= 998244353
    
print(d[n])