from sys import stdin
#再起?
cnt = 0
def move(N, S):
    global cnt
    if N == 0:
        cnt += 1
        cnt %= 998244353
        return
    elif N < 0:
        return
    else:
        for x in S:
            move(N-x, S)
S = set()
N, K = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(K):
    L, R = [int(x) for x in stdin.readline().rstrip().split()]
    for x in range(L, R+1):
        S.add(x)
    move(N, S)
    print(cnt)