import collections

N, K = map(int, input().split())
L = list()
R = list()
for _ in range(K):
    line = list(map(int, input().split()))
    L.append(line[0])
    R.append(line[1])

S = collections.deque()
for left, right in zip(L, R):
    s = range(left, right+1)
    if len(S) == 0:
        S.extend(s)
    elif right < S[0]:
        S.extendleft(s[::-1])
    else:
        S.extend(s)
print(S)

dp = [0] * N
dp[0] = 1
for i in range(1, N):
    for d in S:
        if d > i:
            break
        dp[i] += dp[i - d]
        dp[i] %= 998244353
print(dp[-1])
