n, k = map(int,input().split())
l_r = [ list(map(int, input().split())) for _ in range(k)  ]
s_l = [  list(range(l,r+1)) for l,r in l_r ]
import itertools
s_l = list(itertools.chain.from_iterable(s_l))
d = [0] * n
d[0] = 1

for i in range(1, n):
    c = 0
    for s in s_l:
        if s <= i and d[i-s] > 0:
            c += d[i-s]
    d[i] = c%998244353
print(d[-1]%998244353)