import sys
sys.setrecursionlimit(10000000)

N,K,*f = map(int, open(0).read().split())
LR = [f[i*2:i*2+2] for i in range(K)]
LR.sort()
S = []
for L,R in LR:
    for i in range(L,R+1):
        S.append(i)
mem = [False] * (N+1)
mem[1] = 1

def f(n):
    if mem[n]:
        return mem[n]
    else:
        res = 0
        for x in S:
            if n - x > 0:
                res = (res+f(n-x)) % 998244353
        mem[n] = res
        return res

print(f(N))