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

for j in range(1,N+1):
    for s in S:
        if j + s > N:
            continue
        elif step[j] == 0:
            continue
        step[j+s] += step[j]
        step[j+s] %= 998244353
print(step[N])