from numba import jit
N,K = map(int, input().split())
S = []
for i in range(K):
    L,R = map(int, input().split())
    S += [ j for j in range(L,R+1)]
S = set(S)

step = [0]*(N+1)
step[1] = 1

@jit
def F():
    for j in range(1,N):
        for s in S:
            if j + s > N or step[j] == 0:
                continue
            step[j+s] += (step[j]%998244353)
            step[j+s] %= 998244353
    return step[N]

print(F())