import sys
import numpy as np

n, k = map(int, sys.stdin.buffer.readline().split())
leap = set()
cell = np.array([0]*n, np.int64)
cell[0] = 1 
for x in sys.stdin.buffer.readlines():
    l, r = map(int, x.split())
    leap |= set(range(l,r+1))

for i in range(n):
    if cell[i]:
        for j in leap:
            if i + j < n:
                cell[i+j] += cell[i]

print(cell[-1]%998244353)