N,K = map(int,input().split())
LR = [list(map(int,input().split())) for i in range(K)]
step = []
for l,r in LR:
    for i in range(l,r+1):
        step.append(i)
mod = 998244353
ma = [0] * N
ma[0] = 1
for i in range(N):
    if ma[i] != 0:
        for j in step:
            if i+j < N:
                ma[i+j] += ma[i]
print(ma[N-1]%mod)