N, K = list(map(int,input().split()))

L = [0 for _ in range(N)]
R = [0 for _ in range(N)]

for i in range(K):
    L[i],R[i] = list(map(int,input().split()))

S = []
for i in range(K):
    for s in range(L[i],R[i]+1):
        S.append(s)

A = [0 for _ in range(N)]

A[0] = 1

for i in range(1,N):
    print(i)
    for s in S:
        if s<=i:
            A[i] += A[i-s] % 998244353
    A[i] = A[i] % 998244353

print(A[N-1])
