import numpy as np 

n,k = map(int,input().split())
s = []
for _ in range(k):
    l,r = map(int,input().split())
    s += list(range(l,r+1))
s.sort()

path = np.zeros(n).astype('int')
path[0] = 1

for i in range(n-1):
    if path[i] == 0:
        continue
    for j in s:
        if i+j > n-1:
            break
        path[i+j] += path[i]
print(path[-1]%998244353)