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


def add(a, b, BIGMOD):
    return (a + b) % BIGMOD


MOD = 998244353
S = []
for i in range(K):
    L, R = map(int, input().split())
    for i in range(R - L + 1):
        S.append(L + i)

S = list(set(S))
S = sorted(S)
#print(S)

DP = [0] * N
DP[0] = 1

for i in range(N):
    for s in S:
        if i + s < N:
            DP[i + s] = (DP[i + s] + DP[i]) % MOD
            # print(DP)

print(DP[N - 1] % MOD)
